Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-encoding

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-encoding - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

zstd-codec-browser.js

37

dist/index.js

@@ -15,3 +15,2 @@ "use strict";

const util_1 = require("util");
const zstd_codec_1 = require("zstd-codec");
exports.gzip = util_1.promisify(zlib.gzip);

@@ -23,7 +22,7 @@ exports.gunzip = util_1.promisify(zlib.gunzip);

// Use Node's new built-in Brotli compression, if available, or
// use the wasm-brotli package if not.
// use the brotli-wasm package if not.
exports.brotliCompress = zlib.brotliCompress
? util_1.promisify(zlib.brotliCompress)
: ((buffer, _unusedOpts) => __awaiter(void 0, void 0, void 0, function* () {
const { compress } = yield Promise.resolve().then(() => require('wasm-brotli')); // Sync in node, async in browsers
const { compress } = yield Promise.resolve().then(() => require('brotli-wasm')); // Sync in node, async in browsers
return compress(buffer);

@@ -34,24 +33,26 @@ }));

: ((buffer) => __awaiter(void 0, void 0, void 0, function* () {
const { decompress } = yield Promise.resolve().then(() => require('wasm-brotli')); // Sync in node, async in browsers
const { decompress } = yield Promise.resolve().then(() => require('brotli-wasm')); // Sync in node, async in browsers
return decompress(buffer);
}));
// Zstd is a non-built-in wasm implementation that initializes async. We
// handle this by loading it when the first zstd buffer is decompressed.
// Zstd is a non-built-in wasm implementation that initializes async. We handle this by
// loading it when the first zstd buffer is decompressed. That lets us defer loading
// until that point too, which is good since it's large-ish & rarely used.
let zstd;
const zstdCompress = (buffer, level) => __awaiter(void 0, void 0, void 0, function* () {
const getZstd = () => __awaiter(void 0, void 0, void 0, function* () {
if (!zstd) {
zstd = new Promise((resolve) => zstd_codec_1.ZstdCodec.run((binding) => {
resolve(new binding.Streaming());
zstd = new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
const { ZstdCodec } = yield Promise.resolve().then(() => require('zstd-codec'));
ZstdCodec.run((binding) => {
resolve(new binding.Streaming());
});
}));
}
return (yield zstd).compress(buffer, level);
return yield zstd;
});
const zstdCompress = (buffer, level) => __awaiter(void 0, void 0, void 0, function* () {
return (yield getZstd()).compress(buffer, level);
});
exports.zstdCompress = zstdCompress;
const zstdDecompress = (buffer) => __awaiter(void 0, void 0, void 0, function* () {
if (!zstd) {
zstd = new Promise((resolve) => zstd_codec_1.ZstdCodec.run((binding) => {
resolve(new binding.Streaming());
}));
}
return (yield zstd).decompress(buffer);
return (yield getZstd()).decompress(buffer);
});

@@ -104,3 +105,3 @@ exports.zstdDecompress = zstdDecompress;

}
else if (encoding === 'zstd' && zstd_codec_1.ZstdCodec) {
else if (encoding === 'zstd') {
return asBuffer(yield exports.zstdDecompress(bodyBuffer));

@@ -191,3 +192,3 @@ }

}
else if (encoding === 'zstd' && zstd_codec_1.ZstdCodec) {
else if (encoding === 'zstd') {
return asBuffer(yield exports.zstdCompress(bodyBuffer, level));

@@ -194,0 +195,0 @@ }

{
"name": "http-encoding",
"version": "1.0.1",
"version": "1.1.0",
"description": "Everything you need to handle HTTP message body content-encoding",
"main": "dist/index.js",
"browser": {
"path": false,
"fs": false,
"wasm-brotli": "./wasm-brotli-browser"
"zstd-codec": "./zstd-codec-browser"
},

@@ -16,3 +14,3 @@ "sideEffects": false,

"custom-typings",
"wasm-brotli-browser.js"
"zstd-codec-browser.js"
],

@@ -51,3 +49,3 @@ "scripts": {

"dependencies": {
"wasm-brotli": "^1.0.2",
"brotli-wasm": "^1.0.0",
"zstd-codec": "^0.1.2"

@@ -54,0 +52,0 @@ },

import * as zlib from 'zlib';
import { promisify } from 'util';
import { ZstdCodec, ZstdStreaming } from 'zstd-codec';
import type { ZstdStreaming } from 'zstd-codec';

@@ -22,7 +22,7 @@ export type SUPPORTED_ENCODING =

// Use Node's new built-in Brotli compression, if available, or
// use the wasm-brotli package if not.
// use the brotli-wasm package if not.
export const brotliCompress = zlib.brotliCompress
? promisify(zlib.brotliCompress)
: (async (buffer: Uint8Array, _unusedOpts?: zlib.BrotliOptions): Promise<Uint8Array> => {
const { compress } = await import('wasm-brotli'); // Sync in node, async in browsers
const { compress } = await import('brotli-wasm'); // Sync in node, async in browsers
return compress(buffer);

@@ -34,27 +34,28 @@ });

: (async (buffer: Uint8Array): Promise<Uint8Array> => {
const { decompress } = await import('wasm-brotli'); // Sync in node, async in browsers
const { decompress } = await import('brotli-wasm'); // Sync in node, async in browsers
return decompress(buffer);
});
// Zstd is a non-built-in wasm implementation that initializes async. We
// handle this by loading it when the first zstd buffer is decompressed.
// Zstd is a non-built-in wasm implementation that initializes async. We handle this by
// loading it when the first zstd buffer is decompressed. That lets us defer loading
// until that point too, which is good since it's large-ish & rarely used.
let zstd: Promise<ZstdStreaming> | undefined;
export const zstdCompress = async (buffer: Uint8Array, level?: number): Promise<Uint8Array> => {
const getZstd = async () => {
if (!zstd) {
zstd = new Promise((resolve) => ZstdCodec.run((binding) => {
resolve(new binding.Streaming());
}));
zstd = new Promise(async (resolve) => {
const { ZstdCodec } = await import('zstd-codec');
ZstdCodec.run((binding) => {
resolve(new binding.Streaming());
})
});
}
return await zstd;
};
return (await zstd).compress(buffer, level);
export const zstdCompress = async (buffer: Uint8Array, level?: number): Promise<Uint8Array> => {
return (await getZstd()).compress(buffer, level);
};
export const zstdDecompress = async (buffer: Uint8Array): Promise<Uint8Array> => {
if (!zstd) {
zstd = new Promise((resolve) => ZstdCodec.run((binding) => {
resolve(new binding.Streaming());
}));
}
return (await zstd).decompress(buffer);
return (await getZstd()).decompress(buffer);
};

@@ -105,3 +106,3 @@

return asBuffer(await brotliDecompress(bodyBuffer));
} else if (encoding === 'zstd' && ZstdCodec) {
} else if (encoding === 'zstd') {
return asBuffer(await zstdDecompress(bodyBuffer));

@@ -187,3 +188,3 @@ } else if (encoding === 'amz-1.0') {

} : {}));
} else if (encoding === 'zstd' && ZstdCodec) {
} else if (encoding === 'zstd') {
return asBuffer(await zstdCompress(bodyBuffer, level));

@@ -190,0 +191,0 @@ } else if (!encoding || encoding === 'identity' || encoding === 'amz-1.0') {

Sorry, the diff of this file is not supported yet

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