Socket
Socket
Sign inDemoInstall

minizlib

Package Overview
Dependencies
2
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 1.0.0

118

index.js

@@ -7,49 +7,3 @@ 'use strict'

const constants = {
Z_NO_FLUSH: 0,
Z_PARTIAL_FLUSH: 1,
Z_SYNC_FLUSH: 2,
Z_FULL_FLUSH: 3,
Z_FINISH: 4,
Z_BLOCK: 5,
Z_OK: 0,
Z_STREAM_END: 1,
Z_NEED_DICT: 2,
Z_ERRNO: -1,
Z_STREAM_ERROR: -2,
Z_DATA_ERROR: -3,
Z_MEM_ERROR: -4,
Z_BUF_ERROR: -5,
Z_VERSION_ERROR: -6,
Z_NO_COMPRESSION: 0,
Z_BEST_SPEED: 1,
Z_BEST_COMPRESSION: 9,
Z_DEFAULT_COMPRESSION: -1,
Z_FILTERED: 1,
Z_HUFFMAN_ONLY: 2,
Z_RLE: 3,
Z_FIXED: 4,
Z_DEFAULT_STRATEGY: 0,
ZLIB_VERNUM: 4736,
DEFLATE: 1,
INFLATE: 2,
GZIP: 3,
GUNZIP: 4,
DEFLATERAW: 5,
INFLATERAW: 6,
UNZIP: 7,
Z_MIN_WINDOWBITS: 8,
Z_MAX_WINDOWBITS: 15,
Z_DEFAULT_WINDOWBITS: 15,
Z_MIN_CHUNK: 64,
Z_MAX_CHUNK: Infinity,
Z_DEFAULT_CHUNK: 16384,
Z_MIN_MEMLEVEL: 1,
Z_MAX_MEMLEVEL: 9,
Z_DEFAULT_MEMLEVEL: 8,
Z_MIN_LEVEL: -1,
Z_MAX_LEVEL: 9,
Z_DEFAULT_LEVEL: -1
}
const constants = exports.constants = require('./constants.js')
const MiniPass = require('minipass')

@@ -70,9 +24,10 @@

const isValidFlushFlag = flag =>
flag === constants.Z_NO_FLUSH ||
flag === constants.Z_PARTIAL_FLUSH ||
flag === constants.Z_SYNC_FLUSH ||
flag === constants.Z_FULL_FLUSH ||
flag === constants.Z_FINISH ||
flag === constants.Z_BLOCK
const validFlushFlags = new Set([
constants.Z_NO_FLUSH,
constants.Z_PARTIAL_FLUSH,
constants.Z_SYNC_FLUSH,
constants.Z_FULL_FLUSH,
constants.Z_FINISH,
constants.Z_BLOCK
])

@@ -109,6 +64,6 @@ const strategies = new Set([

this[_chunkSize] = opts.chunkSize || constants.Z_DEFAULT_CHUNK
if (opts.flush && !isValidFlushFlag(opts.flush)) {
if (opts.flush && !validFlushFlags.has(opts.flush)) {
throw new Error('Invalid flush flag: ' + opts.flush)
}
if (opts.finishFlush && !isValidFlushFlag(opts.finishFlush)) {
if (opts.finishFlush && !validFlushFlags.has(opts.finishFlush)) {
throw new Error('Invalid flush flag: ' + opts.finishFlush)

@@ -203,4 +158,8 @@ }

throw new Error('cannot switch params when binding is closed')
// no way to test this without also not supporting params at all
/* istanbul ignore if */
if (!this[_handle].params)
throw new Error('')
throw new Error('not supported in this implementation')
if (level < constants.Z_MIN_LEVEL ||

@@ -210,2 +169,3 @@ level > constants.Z_MAX_LEVEL) {

}
if (!(strategies.has(strategy)))

@@ -218,2 +178,3 @@ throw new TypeError('Invalid strategy: ' + strategy)

this[_handle].params(level, strategy)
/* istanbul ignore else */
if (!this[_hadError]) {

@@ -271,9 +232,19 @@ this[_level] = level

// this is called after each pass of the do()while below
// it returns true if we can push more data through.
const callback = (availInAfter, availOutAfter) => {
assert(this[_handle], 'zlib binding closed')
do {
let res = this[_handle].writeSync(
flushFlag,
chunk, // in
inOff, // in_off
availInBefore, // in_len
this[_buffer], // out
this[_offset], //out_off
availOutBefore // out_len
)
if (this[_hadError])
return
break
let availInAfter = res[0]
let availOutAfter = res[1]
const have = availOutBefore - availOutAfter

@@ -306,22 +277,9 @@ assert(have >= 0, 'have should not go down')

availInBefore = availInAfter
return true
continue
}
return false
}
break
} while (!this[_hadError])
assert(this[_handle], 'zlib binding closed')
let res
do {
res = this[_handle].writeSync(
flushFlag,
chunk, // in
inOff, // in_off
availInBefore, // in_len
this[_buffer], // out
this[_offset], //out_off
availOutBefore // out_len
)
} while (!this[_hadError] && callback(res[0], res[1]))
if (cb)
cb()
return writeReturn

@@ -328,0 +286,0 @@ }

{
"name": "minizlib",
"version": "0.0.1",
"description": "A smaller, faster, zlib stream built on [minipass](http://npm.im/minipass) and Node.js's zlib binding.",
"version": "1.0.0",
"description": "A small fast zlib stream built on [minipass](http://npm.im/minipass) and Node.js's zlib binding.",
"main": "index.js",
"dependencies": {
"minipass": "^1.1.1"
"minipass": "^1.1.6"
},
"scripts": {
"test": "tap test/*.js"
"test": "tap test/*.js --100",
"preversion": "npm test",
"postversion": "npm publish",
"postpublish": "git push origin --all; git push origin --tags"
},

@@ -12,0 +15,0 @@ "repository": {

# minizlib
A smaller, faster, zlib stream built on
[minipass](http://npm.im/minipass) and Node.js's zlib binding.
A tiny fast zlib stream built on [minipass](http://npm.im/minipass)
and Node.js's zlib binding.
**Current Status: Untested Beta** It seems like this works, but I
can't be sure until I have finished writing tests for it.
This module was created to serve the needs of
[node-tar](http://npm.im/tar) v2. If your needs are different, then
it may not be for you.
## How does this differ from the streams in `require('zlib')`?
First, there are no convenience methods to compress or decompress a
buffer. If you want those, use the built-in `zlib` module. This is
only streams.
This module compresses and decompresses the data as fast as you feed
it in. It is synchronous, and runs on the main process thread. Zlib
operations can be high CPU, but they're very fast, and doing it this
way means much less bookkeeping and artificial deferral.
Node's built in zlib streams are built on top of `stream.Transform`.

@@ -15,18 +25,21 @@ They do the maximally safe thing with respect to consistent

This module does support backpressure, and will buffer output chunks
This module _does_ support backpressure, and will buffer output chunks
that are not consumed, but is less of a mediator between the input and
output. There is no high or low watermarks, no state objects, and so
on. If you write, data will be emitted right away. If you write
everything synchronously in one tick, and someone is listening to the
artificial async deferrals. It will not protect you from Zalgo.
If you write, data will be emitted right away. If you write
everything synchronously in one tick, and you are listening to the
`data` event to consume it, then it'll all be emitted right away in
that same tick. It is thus the responsibility of the reader and
writer to manage their own consumption.
that same tick. If you want data to be emitted in the next tick, then
write it in the next tick.
Additionally, the compression and decompression is done on the main
thread, rather than offloading to a worker thread asynchronously.
It is thus the responsibility of the reader and writer to manage their
own consumption and process execution flow.
The goal is to compress and decompress as fast as possible, even for
files that are too large to do all in one pass.
files that are too large to store all in one buffer.
This module was created to serve the needs of
[node-tar](http://npm.im/tar) v2.
The API is very similar to the built-in zlib module. There are
classes that you instantiate with `new` and they are streams that can
be piped together.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc