This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+22
View File
@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+47
View File
@@ -0,0 +1,47 @@
# inflation
[![NPM version](https://badge.fury.io/js/inflation.svg)](http://badge.fury.io/js/inflation)
[![CI](https://github.com/stream-utils/inflation/actions/workflows/nodejs.yml/badge.svg)](https://github.com/stream-utils/inflation/actions/workflows/nodejs.yml)
Automatically unzip an HTTP stream.
## API
```js
var inflate = require('inflation')
```
### inflate(stream, options)
Returns a stream that emits inflated data from the given stream.
Options:
- `encoding` - The encoding of the stream (`gzip` or `deflate`).
If not given, will look in `stream.headers['content-encoding']`.
- `brotli` - [`BrotliOptions`](https://nodejs.org/api/zlib.html#class-brotlioptions) to use for Brotli decompression
## Example
```js
var inflate = require('inflation')
var raw = require('raw-body')
http.createServer(function (req, res) {
raw(inflate(req), 'utf-8', function (err, string) {
console.dir(string)
})
})
```
<!-- GITCONTRIBUTOR_START -->
## Contributors
|[<img src="https://avatars.githubusercontent.com/u/67512?v=4" width="100px;"/><br/><sub><b>dougwilson</b></sub>](https://github.com/dougwilson)<br/>|[<img src="https://avatars.githubusercontent.com/u/73755?v=4" width="100px;"/><br/><sub><b>bminer</b></sub>](https://github.com/bminer)<br/>|[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|
| :---: | :---: | :---: |
This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Sat Oct 14 2023 12:55:08 GMT+0800`.
<!-- GITCONTRIBUTOR_END -->
+41
View File
@@ -0,0 +1,41 @@
var zlib = require('zlib')
module.exports = inflate
function inflate(stream, options) {
if (!stream) {
throw new TypeError('argument stream is required')
}
options = options || {}
var encoding = options.encoding
|| (stream.headers && stream.headers['content-encoding'])
|| 'identity'
var decompression
switch (encoding) {
case 'gzip':
case 'deflate':
delete options.brotli
delete options.encoding
decompression = zlib.createUnzip(options)
break
case 'br':
if (zlib.createBrotliDecompress) {
decompression = zlib.createBrotliDecompress(options.brotli)
}
break
case 'identity':
return stream
}
if (!decompression) {
var err = new Error('Unsupported Content-Encoding: ' + encoding)
err.status = 415
throw err
}
return stream.pipe(decompression)
}
+34
View File
@@ -0,0 +1,34 @@
{
"name": "inflation",
"description": "Easily unzip an HTTP stream",
"version": "2.1.0",
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)",
"license": "MIT",
"repository": "stream-utils/inflation",
"keywords": [
"decompress",
"unzip",
"inflate",
"zlib",
"gunzip",
"brotli"
],
"devDependencies": {
"git-contributor": "^2.1.5",
"istanbul": "0.2.10",
"mocha": "^10.2.0",
"readable-stream": "~1.0.27",
"should": "4.0.4"
},
"engines": {
"node": ">= 0.8.0"
},
"scripts": {
"test": "mocha --reporter spec --bail test/*.js",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot test/",
"contributor": "git-contributor"
},
"files": [
"index.js"
]
}