Socket
Socket
Sign inDemoInstall

@tinyhttp/content-disposition

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinyhttp/content-disposition - npm Package Compare versions

Comparing version 2.0.4 to 2.0.5

7

package.json
{
"name": "@tinyhttp/content-disposition",
"description": "content-disposition rewrite in TypeScript with ESM and CommonJS targets",
"version": "2.0.4",
"description": "content-disposition rewrite in TypeScript",
"version": "2.0.5",
"homepage": "https://tinyhttp.v1rtl.site",

@@ -26,3 +26,4 @@ "funding": {

"build": "rollup -c ../../build/defaultConfig.js"
}
},
"readme": "# @tinyhttp/content-disposition\n\n> [`content-disposition`](https://github.com/jshttp/content-disposition) rewrite in TypeScript.\n\nCreate and parse HTTP `Content-Disposition` header\n\n## Install\n\n```sh\npnpm i @tinyhttp/content-disposition\n```\n\n## API\n\n```ts\nimport { contentDisposition, parse } from '@tinyhttp/content-disposition'\n```\n\n### `contentDisposition(filename)`\n\nCreate an attachment `Content-Disposition` header value using the given file name,\nif supplied. The `filename` is optional and if no file name is desired, but you\nwant to specify `options`, set `filename` to `undefined`.\n\n```js\nres.setHeader('Content-Disposition', contentDisposition('∫ maths.pdf'))\n```\n\n**note** HTTP headers are of the ISO-8859-1 character set. If you are writing this\nheader through a means different from `setHeader` in Node.js, you'll want to specify\nthe `'binary'` encoding in Node.js.\n\n#### Options\n\n`contentDisposition` accepts these properties in the options object.\n\n##### `fallback`\n\nIf the `filename` option is outside ISO-8859-1, then the file name is actually\nstored in a supplemental field for clients that support Unicode file names and\na ISO-8859-1 version of the file name is automatically generated.\n\nThis specifies the ISO-8859-1 file name to override the automatic generation or\ndisables the generation all together, defaults to `true`.\n\n- A string will specify the ISO-8859-1 file name to use in place of automatic\n generation.\n- `false` will disable including a ISO-8859-1 file name and only include the\n Unicode version (unless the file name is already ISO-8859-1).\n- `true` will enable automatic generation if the file name is outside ISO-8859-1.\n\nIf the `filename` option is ISO-8859-1 and this option is specified and has a\ndifferent value, then the `filename` option is encoded in the extended field\nand this set as the fallback field, even though they are both ISO-8859-1.\n\n##### `type`\n\nSpecifies the disposition type, defaults to `\"attachment\"`. This can also be\n`\"inline\"`, or any other value (all values except inline are treated like\n`attachment`, but can convey additional information if both parties agree to\nit). The type is normalized to lower-case.\n\n### `contentDisposition.parse(string)`\n\n```js\ncontentDisposition.parse('attachment; filename=\"EURO rates.txt\"; filename*=UTF-8\\'\\'%e2%82%ac%20rates.txt')\n```\n\nParse a `Content-Disposition` header string. This automatically handles extended\n(\"Unicode\") parameters by decoding them and providing them under the standard\nparameter name. This will return an object with the following properties (examples\nare shown for the string `'attachment; filename=\"EURO rates.txt\"; filename*=UTF-8\\'\\'%e2%82%ac%20rates.txt'`):\n\n- `type`: The disposition type (always lower case). Example: `'attachment'`\n\n- `parameters`: An object of the parameters in the disposition (name of parameter\n always lower case and extended versions replace non-extended versions). Example:\n `{filename: \"€ rates.txt\"}`\n\n## Example\n\nThis simple example shows how to use `accepts` to return a different typed\nrespond body based on what the client wants to accept. The server lists it's\npreferences in order and will get back the best match between the client and\nserver.\n\n```ts\nimport { contentDisposition } from '@tinyhttp/content-disposition'\nimport destroy from 'destroy'\nimport fs from 'fs'\nimport { createServer } from 'http'\nimport onFinished from 'on-finished'\n\nconst filePath = '/path/to/public/plans.pdf'\n\ncreateServer((req, res) => {\n res.setHeader('Content-Type', 'application/pdf')\n res.setHeader('Content-Disposition', contentDisposition(filePath))\n\n const stream = fs.createReadStream(filePath)\n stream.pipe(res)\n onFinished(res, () => destroy(stream))\n})\n```\n"
}
# @tinyhttp/content-disposition
> [`content-disposition`](https://github.com/jshttp/content-disposition) rewrite in TypeScript with ESM and CommonJS targets.
> [`content-disposition`](https://github.com/jshttp/content-disposition) rewrite in TypeScript.

@@ -5,0 +5,0 @@ Create and parse HTTP `Content-Disposition` header

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc