* Create a bare Zstd handle. * @returns {{ handle: object, writeState: Uint32Array, chunkSize: number }}
(mode, options, processCallback, onError)
| 248 | * @returns {{ handle: object, writeState: Uint32Array, chunkSize: number }} |
| 249 | */ |
| 250 | function createZstdHandle(mode, options, processCallback, onError) { |
| 251 | const isCompress = mode === ZSTD_COMPRESS; |
| 252 | |
| 253 | // Validate before creating native handle. |
| 254 | const chunkSize = validateChunkSize(options); |
| 255 | const dictionary = validateDictionary(options.dictionary); |
| 256 | const maxParam = isCompress ? kMaxZstdCParam : kMaxZstdDParam; |
| 257 | validateParams(options.params, maxParam, ERR_ZSTD_INVALID_PARAM); |
| 258 | |
| 259 | const pledgedSrcSize = options.pledgedSrcSize; |
| 260 | if (pledgedSrcSize !== undefined) { |
| 261 | if (typeof pledgedSrcSize !== 'number' || NumberIsNaN(pledgedSrcSize)) { |
| 262 | throw new ERR_INVALID_ARG_TYPE('options.pledgedSrcSize', 'number', |
| 263 | pledgedSrcSize); |
| 264 | } |
| 265 | if (pledgedSrcSize < 0) { |
| 266 | throw new ERR_OUT_OF_RANGE('options.pledgedSrcSize', '>= 0', |
| 267 | pledgedSrcSize); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | const handle = isCompress ? |
| 272 | new binding.ZstdCompress() : new binding.ZstdDecompress(); |
| 273 | const writeState = new Uint32Array(2); |
| 274 | |
| 275 | const initArray = isCompress ? zstdInitCParamsArray : zstdInitDParamsArray; |
| 276 | TypedArrayPrototypeFill(initArray, -1); |
| 277 | if (options.params) { |
| 278 | const params = options.params; |
| 279 | const keys = ObjectKeys(params); |
| 280 | for (let i = 0; i < keys.length; i++) { |
| 281 | const key = +keys[i]; |
| 282 | initArray[key] = params[keys[i]]; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | handle.onerror = onError; |
| 287 | handle.init( |
| 288 | initArray, |
| 289 | pledgedSrcSize, |
| 290 | writeState, |
| 291 | processCallback, |
| 292 | dictionary, |
| 293 | ); |
| 294 | |
| 295 | return { __proto__: null, handle, writeState, chunkSize }; |
| 296 | } |
| 297 | |
| 298 | // --------------------------------------------------------------------------- |
| 299 | // Core: makeZlibTransform |
no test coverage detected
searching dependent graphs…