Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function decodeContent (content: Buffer, encoding: string, charset: Charset) {
if (encoding === GZIP_CONTENT_ENCODING) {
// NOTE: https://github.com/request/request/pull/2492/files
// Be more lenient with decoding compressed responses, since (very rarely)
// servers send slightly invalid gzip responses that are still accepted
// by common browsers.
// Always using Z_SYNC_FLUSH is what cURL does.
// GH-1915
content = await gunzip(content, { flush: zlib.Z_SYNC_FLUSH, finishFlush: zlib.Z_SYNC_FLUSH });
}
else if (encoding === DEFLATE_CONTENT_ENCODING)
content = await inflateWithFallback(content);
else if (encoding === BROTLI_CONTENT_ENCODING)
content = Buffer.from(require('brotli').decompress(content));
charset.fromBOM(content);
return charsetEncoder.decode(content, charset.get());
}
transformVersion = 0;
var transformLength = rb.read(Type.BASE128);
}
totalSize += origLength;
index.push({
flags: flag,
tag: tag,
origLength: origLength
});
}
// TODO: Upgrade to Node v6.x so we can use Buffer.from.
var data = new Buffer(brotli.decompress(buffer.slice(rb.byteOffset, rb.byteOffset + totalSize)));
var offset = 0;
index.forEach(function (table) {
font.tables[table.tag] = data.slice(offset, offset + util.pad(table.origLength));
offset += table.origLength;
});
} else if (signature === Format.TRUETYPE || signature === Format.OPENTYPE) {
font.header = rb.read(sfnt.Header);
var index = rb.readArray(sfnt.OffsetTable, font.header.numTables);
index.forEach(function (table) {
font.tables[table.tag] = buffer.slice(table.offset, table.offset + util.pad(table.length));
});
}
for (var table in TABLES) {
export function serialiseBuffer(
buffer: Buffer,
headers: Headers
): PersistedBuffer {
const header = headers["content-encoding"];
const contentEncoding = typeof header === "string" ? header : undefined;
const originalBuffer = buffer;
let compression: CompressionAlgorithm = "none";
if (contentEncoding === "br") {
buffer = Buffer.from(brotli.decompress(buffer));
compression = "br";
}
if (contentEncoding === "gzip") {
buffer = gunzipSync(buffer);
compression = "gzip";
}
const utf8Representation = buffer.toString("utf8");
try {
// Can it be safely stored and recreated in YAML?
const recreatedBuffer = Buffer.from(
yaml.safeLoad(yaml.safeDump(utf8Representation)),
"utf8"
);
if (Buffer.compare(buffer, recreatedBuffer) === 0) {
// Yes, we can store it in YAML.
return {
});
} else if (isServerDeflated && originContentLen) {
refactContentEncoding();
zlib.inflateRaw(serverResData, (err, buff) => {
if (err) {
rejectParsing(err);
} else {
fulfill(buff);
}
});
} else if (isBrotlied && originContentLen) {
refactContentEncoding();
try {
// an Unit8Array returned by decompression
const result = brotliTorb.decompress(serverResData);
fulfill(Buffer.from(result));
} catch (e) {
rejectParsing(e);
}
} else {
fulfill(serverResData);
}
}
}).then((serverResData) => {
resolve({
});
} else if (isServerDeflated && originContentLen) {
refactContentEncoding();
zlib.inflateRaw(serverResData, (err, buff) => { // TODO test case to cover
if (err) {
rejectParsing(err);
} else {
fulfill(buff);
}
});
} else if (isBrotlied && originContentLen) {
refactContentEncoding();
try {
// an Unit8Array returned by decompression
const result = brotliTorb.decompress(serverResData);
fulfill(Buffer.from(result));
} catch (e) {
rejectParsing(e);
}
} else {
fulfill(serverResData);
}
}
}).then((serverResData) => {
resolve({
function inflate_brotli(value) {
return new Buffer(brotli.decompress(value));
}