block-stream2
Advanced tools
Comparing version 2.0.0 to 2.1.0
25
index.js
@@ -28,6 +28,25 @@ const { Transform } = require('readable-stream') | ||
while (this._bufferedBytes >= this.size) { | ||
const b = Buffer.concat(this._buffered) | ||
this._bufferedBytes -= this.size | ||
this.push(b.slice(0, this.size)) | ||
this._buffered = [ b.slice(this.size, b.length) ] | ||
// Assemble the buffers that will compose the final block | ||
const blockBufs = [] | ||
let blockBufsBytes = 0 | ||
while (blockBufsBytes < this.size) { | ||
const b = this._buffered.shift() | ||
if (blockBufsBytes + b.length <= this.size) { | ||
blockBufs.push(b) | ||
blockBufsBytes += b.length | ||
} else { | ||
// If the last buffer is larger than needed for the block, just | ||
// use the needed part | ||
const neededSize = this.size - blockBufsBytes | ||
blockBufs.push(b.slice(0, neededSize)) | ||
blockBufsBytes += neededSize | ||
this._buffered.unshift(b.slice(neededSize)) | ||
} | ||
} | ||
// Then concat just those buffers, leaving the rest untouched in _buffered | ||
this.push(Buffer.concat(blockBufs, this.size)) | ||
} | ||
@@ -34,0 +53,0 @@ next() |
{ | ||
"name": "block-stream2", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "transform input into equally-sized blocks of output", | ||
@@ -10,6 +10,7 @@ "main": "index.js", | ||
"devDependencies": { | ||
"standard": "^16.0.3", | ||
"tape": "^4.2.2" | ||
}, | ||
"scripts": { | ||
"test": "tape test/*.js" | ||
"test": "standard && tape test/*.js" | ||
}, | ||
@@ -16,0 +17,0 @@ "repository": { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
5228
56
0
2