brotli-wasm
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "brotli-wasm", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A reliable compressor and decompressor for Brotli, supporting node & browsers via wasm", | ||
@@ -5,0 +5,0 @@ "main": "./pkg.node/brotli_wasm.js", |
import * as wasm from './brotli_wasm_bg.wasm'; | ||
const heap = new Array(32).fill(undefined); | ||
heap.push(undefined, null, true, false); | ||
function getObject(idx) { return heap[idx]; } | ||
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; | ||
@@ -21,6 +27,2 @@ | ||
const heap = new Array(32).fill(undefined); | ||
heap.push(undefined, null, true, false); | ||
let heap_next = heap.length; | ||
@@ -37,4 +39,67 @@ | ||
function getObject(idx) { return heap[idx]; } | ||
let WASM_VECTOR_LEN = 0; | ||
const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder; | ||
let cachedTextEncoder = new lTextEncoder('utf-8'); | ||
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' | ||
? function (arg, view) { | ||
return cachedTextEncoder.encodeInto(arg, view); | ||
} | ||
: function (arg, view) { | ||
const buf = cachedTextEncoder.encode(arg); | ||
view.set(buf); | ||
return { | ||
read: arg.length, | ||
written: buf.length | ||
}; | ||
}); | ||
function passStringToWasm0(arg, malloc, realloc) { | ||
if (realloc === undefined) { | ||
const buf = cachedTextEncoder.encode(arg); | ||
const ptr = malloc(buf.length); | ||
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); | ||
WASM_VECTOR_LEN = buf.length; | ||
return ptr; | ||
} | ||
let len = arg.length; | ||
let ptr = malloc(len); | ||
const mem = getUint8Memory0(); | ||
let offset = 0; | ||
for (; offset < len; offset++) { | ||
const code = arg.charCodeAt(offset); | ||
if (code > 0x7F) break; | ||
mem[ptr + offset] = code; | ||
} | ||
if (offset !== len) { | ||
if (offset !== 0) { | ||
arg = arg.slice(offset); | ||
} | ||
ptr = realloc(ptr, len, len = offset + arg.length * 3); | ||
const view = getUint8Memory0().subarray(ptr + offset, ptr + len); | ||
const ret = encodeString(arg, view); | ||
offset += ret.written; | ||
} | ||
WASM_VECTOR_LEN = offset; | ||
return ptr; | ||
} | ||
let cachegetInt32Memory0 = null; | ||
function getInt32Memory0() { | ||
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) { | ||
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer); | ||
} | ||
return cachegetInt32Memory0; | ||
} | ||
function dropObject(idx) { | ||
@@ -52,4 +117,2 @@ if (idx < 36) return; | ||
let WASM_VECTOR_LEN = 0; | ||
function passArray8ToWasm0(arg, malloc) { | ||
@@ -62,8 +125,8 @@ const ptr = malloc(arg.length * 1); | ||
let cachegetInt32Memory0 = null; | ||
function getInt32Memory0() { | ||
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) { | ||
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer); | ||
} | ||
return cachegetInt32Memory0; | ||
let stack_pointer = 32; | ||
function addBorrowedObject(obj) { | ||
if (stack_pointer == 1) throw new Error('out of js stack'); | ||
heap[--stack_pointer] = obj; | ||
return stack_pointer; | ||
} | ||
@@ -76,5 +139,6 @@ | ||
* @param {Uint8Array} buf | ||
* @param {any} raw_options | ||
* @returns {Uint8Array} | ||
*/ | ||
export function compress(buf) { | ||
export function compress(buf, raw_options) { | ||
try { | ||
@@ -84,3 +148,3 @@ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
var len0 = WASM_VECTOR_LEN; | ||
wasm.compress(retptr, ptr0, len0); | ||
wasm.compress(retptr, ptr0, len0, addBorrowedObject(raw_options)); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
@@ -93,2 +157,3 @@ var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
heap[stack_pointer++] = undefined; | ||
} | ||
@@ -117,57 +182,13 @@ } | ||
const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder; | ||
export function __wbindgen_is_undefined(arg0) { | ||
var ret = getObject(arg0) === undefined; | ||
return ret; | ||
}; | ||
let cachedTextEncoder = new lTextEncoder('utf-8'); | ||
export function __wbindgen_is_object(arg0) { | ||
const val = getObject(arg0); | ||
var ret = typeof(val) === 'object' && val !== null; | ||
return ret; | ||
}; | ||
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' | ||
? function (arg, view) { | ||
return cachedTextEncoder.encodeInto(arg, view); | ||
} | ||
: function (arg, view) { | ||
const buf = cachedTextEncoder.encode(arg); | ||
view.set(buf); | ||
return { | ||
read: arg.length, | ||
written: buf.length | ||
}; | ||
}); | ||
function passStringToWasm0(arg, malloc, realloc) { | ||
if (realloc === undefined) { | ||
const buf = cachedTextEncoder.encode(arg); | ||
const ptr = malloc(buf.length); | ||
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); | ||
WASM_VECTOR_LEN = buf.length; | ||
return ptr; | ||
} | ||
let len = arg.length; | ||
let ptr = malloc(len); | ||
const mem = getUint8Memory0(); | ||
let offset = 0; | ||
for (; offset < len; offset++) { | ||
const code = arg.charCodeAt(offset); | ||
if (code > 0x7F) break; | ||
mem[ptr + offset] = code; | ||
} | ||
if (offset !== len) { | ||
if (offset !== 0) { | ||
arg = arg.slice(offset); | ||
} | ||
ptr = realloc(ptr, len, len = offset + arg.length * 3); | ||
const view = getUint8Memory0().subarray(ptr + offset, ptr + len); | ||
const ret = encodeString(arg, view); | ||
offset += ret.written; | ||
} | ||
WASM_VECTOR_LEN = offset; | ||
return ptr; | ||
} | ||
export function __wbindgen_string_new(arg0, arg1) { | ||
@@ -178,2 +199,11 @@ var ret = getStringFromWasm0(arg0, arg1); | ||
export function __wbindgen_json_serialize(arg0, arg1) { | ||
const obj = getObject(arg1); | ||
var ret = JSON.stringify(obj === undefined ? null : obj); | ||
var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len0 = WASM_VECTOR_LEN; | ||
getInt32Memory0()[arg0 / 4 + 1] = len0; | ||
getInt32Memory0()[arg0 / 4 + 0] = ptr0; | ||
}; | ||
export function __wbg_new_59cb74e423758ede() { | ||
@@ -180,0 +210,0 @@ var ret = new Error(); |
/* tslint:disable */ | ||
/* eslint-disable */ | ||
export const memory: WebAssembly.Memory; | ||
export function compress(a: number, b: number, c: number): void; | ||
export function compress(a: number, b: number, c: number, d: number): void; | ||
export function decompress(a: number, b: number, c: number): void; | ||
@@ -62,5 +62,5 @@ export function BrotliDecoderCreateInstance(a: number, b: number, c: number): number; | ||
export function BrotliEncoderFreeUsize(a: number, b: number, c: number): void; | ||
export function __wbindgen_malloc(a: number): number; | ||
export function __wbindgen_realloc(a: number, b: number, c: number): number; | ||
export function __wbindgen_add_to_stack_pointer(a: number): number; | ||
export function __wbindgen_malloc(a: number): number; | ||
export function __wbindgen_free(a: number, b: number): void; | ||
export function __wbindgen_realloc(a: number, b: number, c: number): number; |
@@ -7,7 +7,11 @@ /* tslint:disable */ | ||
*/ | ||
export function compress(buf: Uint8Array): Uint8Array; | ||
/** | ||
* @param {Uint8Array} buf | ||
* @returns {Uint8Array} | ||
*/ | ||
export function decompress(buf: Uint8Array): Uint8Array; | ||
type Options = { | ||
quality?: number | ||
}; | ||
export function compress(buf: Uint8Array, options?: Options): Uint8Array; | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
export const memory: WebAssembly.Memory; | ||
export function compress(a: number, b: number, c: number): void; | ||
export function compress(a: number, b: number, c: number, d: number): void; | ||
export function decompress(a: number, b: number, c: number): void; | ||
@@ -62,5 +62,5 @@ export function BrotliDecoderCreateInstance(a: number, b: number, c: number): number; | ||
export function BrotliEncoderFreeUsize(a: number, b: number, c: number): void; | ||
export function __wbindgen_malloc(a: number): number; | ||
export function __wbindgen_realloc(a: number, b: number, c: number): number; | ||
export function __wbindgen_add_to_stack_pointer(a: number): number; | ||
export function __wbindgen_malloc(a: number): number; | ||
export function __wbindgen_free(a: number, b: number): void; | ||
export function __wbindgen_realloc(a: number, b: number, c: number): number; |
@@ -7,7 +7,11 @@ /* tslint:disable */ | ||
*/ | ||
export function compress(buf: Uint8Array): Uint8Array; | ||
/** | ||
* @param {Uint8Array} buf | ||
* @returns {Uint8Array} | ||
*/ | ||
export function decompress(buf: Uint8Array): Uint8Array; | ||
type Options = { | ||
quality?: number | ||
}; | ||
export function compress(buf: Uint8Array, options?: Options): Uint8Array; | ||
@@ -6,2 +6,8 @@ let imports = {}; | ||
const heap = new Array(32).fill(undefined); | ||
heap.push(undefined, null, true, false); | ||
function getObject(idx) { return heap[idx]; } | ||
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); | ||
@@ -23,6 +29,2 @@ | ||
const heap = new Array(32).fill(undefined); | ||
heap.push(undefined, null, true, false); | ||
let heap_next = heap.length; | ||
@@ -39,4 +41,65 @@ | ||
function getObject(idx) { return heap[idx]; } | ||
let WASM_VECTOR_LEN = 0; | ||
let cachedTextEncoder = new TextEncoder('utf-8'); | ||
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' | ||
? function (arg, view) { | ||
return cachedTextEncoder.encodeInto(arg, view); | ||
} | ||
: function (arg, view) { | ||
const buf = cachedTextEncoder.encode(arg); | ||
view.set(buf); | ||
return { | ||
read: arg.length, | ||
written: buf.length | ||
}; | ||
}); | ||
function passStringToWasm0(arg, malloc, realloc) { | ||
if (realloc === undefined) { | ||
const buf = cachedTextEncoder.encode(arg); | ||
const ptr = malloc(buf.length); | ||
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); | ||
WASM_VECTOR_LEN = buf.length; | ||
return ptr; | ||
} | ||
let len = arg.length; | ||
let ptr = malloc(len); | ||
const mem = getUint8Memory0(); | ||
let offset = 0; | ||
for (; offset < len; offset++) { | ||
const code = arg.charCodeAt(offset); | ||
if (code > 0x7F) break; | ||
mem[ptr + offset] = code; | ||
} | ||
if (offset !== len) { | ||
if (offset !== 0) { | ||
arg = arg.slice(offset); | ||
} | ||
ptr = realloc(ptr, len, len = offset + arg.length * 3); | ||
const view = getUint8Memory0().subarray(ptr + offset, ptr + len); | ||
const ret = encodeString(arg, view); | ||
offset += ret.written; | ||
} | ||
WASM_VECTOR_LEN = offset; | ||
return ptr; | ||
} | ||
let cachegetInt32Memory0 = null; | ||
function getInt32Memory0() { | ||
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) { | ||
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer); | ||
} | ||
return cachegetInt32Memory0; | ||
} | ||
function dropObject(idx) { | ||
@@ -54,4 +117,2 @@ if (idx < 36) return; | ||
let WASM_VECTOR_LEN = 0; | ||
function passArray8ToWasm0(arg, malloc) { | ||
@@ -64,8 +125,8 @@ const ptr = malloc(arg.length * 1); | ||
let cachegetInt32Memory0 = null; | ||
function getInt32Memory0() { | ||
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) { | ||
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer); | ||
} | ||
return cachegetInt32Memory0; | ||
let stack_pointer = 32; | ||
function addBorrowedObject(obj) { | ||
if (stack_pointer == 1) throw new Error('out of js stack'); | ||
heap[--stack_pointer] = obj; | ||
return stack_pointer; | ||
} | ||
@@ -78,5 +139,6 @@ | ||
* @param {Uint8Array} buf | ||
* @param {any} raw_options | ||
* @returns {Uint8Array} | ||
*/ | ||
module.exports.compress = function(buf) { | ||
module.exports.compress = function(buf, raw_options) { | ||
try { | ||
@@ -86,3 +148,3 @@ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
var len0 = WASM_VECTOR_LEN; | ||
wasm.compress(retptr, ptr0, len0); | ||
wasm.compress(retptr, ptr0, len0, addBorrowedObject(raw_options)); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
@@ -95,2 +157,3 @@ var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
heap[stack_pointer++] = undefined; | ||
} | ||
@@ -119,55 +182,13 @@ }; | ||
let cachedTextEncoder = new TextEncoder('utf-8'); | ||
module.exports.__wbindgen_is_undefined = function(arg0) { | ||
var ret = getObject(arg0) === undefined; | ||
return ret; | ||
}; | ||
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' | ||
? function (arg, view) { | ||
return cachedTextEncoder.encodeInto(arg, view); | ||
} | ||
: function (arg, view) { | ||
const buf = cachedTextEncoder.encode(arg); | ||
view.set(buf); | ||
return { | ||
read: arg.length, | ||
written: buf.length | ||
}; | ||
}); | ||
module.exports.__wbindgen_is_object = function(arg0) { | ||
const val = getObject(arg0); | ||
var ret = typeof(val) === 'object' && val !== null; | ||
return ret; | ||
}; | ||
function passStringToWasm0(arg, malloc, realloc) { | ||
if (realloc === undefined) { | ||
const buf = cachedTextEncoder.encode(arg); | ||
const ptr = malloc(buf.length); | ||
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); | ||
WASM_VECTOR_LEN = buf.length; | ||
return ptr; | ||
} | ||
let len = arg.length; | ||
let ptr = malloc(len); | ||
const mem = getUint8Memory0(); | ||
let offset = 0; | ||
for (; offset < len; offset++) { | ||
const code = arg.charCodeAt(offset); | ||
if (code > 0x7F) break; | ||
mem[ptr + offset] = code; | ||
} | ||
if (offset !== len) { | ||
if (offset !== 0) { | ||
arg = arg.slice(offset); | ||
} | ||
ptr = realloc(ptr, len, len = offset + arg.length * 3); | ||
const view = getUint8Memory0().subarray(ptr + offset, ptr + len); | ||
const ret = encodeString(arg, view); | ||
offset += ret.written; | ||
} | ||
WASM_VECTOR_LEN = offset; | ||
return ptr; | ||
} | ||
module.exports.__wbindgen_string_new = function(arg0, arg1) { | ||
@@ -178,2 +199,11 @@ var ret = getStringFromWasm0(arg0, arg1); | ||
module.exports.__wbindgen_json_serialize = function(arg0, arg1) { | ||
const obj = getObject(arg1); | ||
var ret = JSON.stringify(obj === undefined ? null : obj); | ||
var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len0 = WASM_VECTOR_LEN; | ||
getInt32Memory0()[arg0 / 4 + 1] = len0; | ||
getInt32Memory0()[arg0 / 4 + 0] = ptr0; | ||
}; | ||
module.exports.__wbg_new_59cb74e423758ede = function() { | ||
@@ -180,0 +210,0 @@ var ret = new Error(); |
@@ -23,2 +23,7 @@ # brotli-wasm [![Build Status](https://github.com/httptoolkit/brotli-wasm/workflows/CI/badge.svg)](https://github.com/httptoolkit/brotli-wasm/actions) [![Available on NPM](https://img.shields.io/npm/v/brotli-wasm.svg)](https://npmjs.com/package/brotli-wasm) | ||
In both builds, the module exposes two methods: | ||
* `compress(Buffer, [options])` - compresses a buffer using Brotli, returning the compressed buffer. An optional options object can be provided. The only currently supported option is `quality`: a number between 1 and 11. | ||
* `decompress(Buffer)` - decompresses a buffer using Brotli, returning the original raw data. | ||
In node.js: | ||
@@ -25,0 +30,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2871637
545
62