mirror of
https://codeberg.org/teddit/teddit.git
synced 2026-04-18 21:45:06 -04:00
initial commit
This commit is contained in:
54
node_modules/postman-request/lib/brotli.js
generated
vendored
Normal file
54
node_modules/postman-request/lib/brotli.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
'use strict'
|
||||
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
var Transform = require('stream').Transform
|
||||
var zlib = require('zlib')
|
||||
var inherits = require('util').inherits
|
||||
var createBrotliDecompress = zlib.createBrotliDecompress
|
||||
|
||||
if (typeof createBrotliDecompress !== 'function') {
|
||||
var brotliDecompressBuffer = require('brotli/decompress')
|
||||
|
||||
var BrotliDecompress = function BrotliDecompress (options) {
|
||||
this.options = options
|
||||
this.chunks = []
|
||||
|
||||
Transform.call(this, options)
|
||||
}
|
||||
|
||||
inherits(BrotliDecompress, Transform)
|
||||
|
||||
BrotliDecompress.prototype._transform = function (chunk, encoding, callback) {
|
||||
this.chunks.push(chunk)
|
||||
return callback()
|
||||
}
|
||||
|
||||
BrotliDecompress.prototype._flush = function (callback) {
|
||||
var body
|
||||
|
||||
try {
|
||||
body = Buffer.from(brotliDecompressBuffer(Buffer.concat(this.chunks)))
|
||||
} catch (err) {
|
||||
return callback(err)
|
||||
}
|
||||
|
||||
this.push(body)
|
||||
return callback()
|
||||
}
|
||||
|
||||
createBrotliDecompress = function createBrotliDecompress (options) {
|
||||
return new BrotliDecompress(options)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports a function that can be used to decompress a Brotli stream.
|
||||
* supports faster and native brotli, if available, else falls back to userland
|
||||
* module
|
||||
*
|
||||
* @function
|
||||
*
|
||||
* @param {Object} options BrotliDecompress options
|
||||
* @returns {stream.Transform} A BrotliDecompress Transform function
|
||||
*/
|
||||
module.exports.createBrotliDecompress = createBrotliDecompress
|
||||
Reference in New Issue
Block a user