Socket
Socket
Sign inDemoInstall

bl

Package Overview
Dependencies
Maintainers
2
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bl - npm Package Compare versions

Comparing version 5.0.0 to 5.1.0

.github/dependabot.yml

94

package.json
{
"name": "bl",
"version": "5.0.0",
"version": "5.1.0",
"description": "Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too!",

@@ -9,3 +9,6 @@ "license": "MIT",

"lint": "standard *.js test/*.js",
"test": "npm run lint && node test/test.js | faucet"
"test": "npm run lint && npm run test:types && node test/test.js | faucet",
"test:ci": "npm run lint && node test/test.js && npm run test:types",
"test:types": "tsc --allowJs --noEmit test/test.js",
"build": "true"
},

@@ -34,6 +37,89 @@ "repository": {

"devDependencies": {
"@types/readable-stream": "^2.3.13",
"faucet": "~0.0.1",
"standard": "^16.0.3",
"tape": "^5.2.2"
"standard": "^17.0.0",
"tape": "^5.2.2",
"typescript": "~4.7.3"
},
"release": {
"branches": [
"master"
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits",
"releaseRules": [
{
"breaking": true,
"release": "major"
},
{
"revert": true,
"release": "patch"
},
{
"type": "feat",
"release": "minor"
},
{
"type": "fix",
"release": "patch"
},
{
"type": "chore",
"release": "patch"
},
{
"type": "docs",
"release": "patch"
},
{
"type": "test",
"release": "patch"
},
{
"scope": "no-release",
"release": false
}
]
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"section": "Trivial Changes"
},
{
"type": "docs",
"section": "Trivial Changes"
},
{
"type": "test",
"section": "Tests"
}
]
}
}
],
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
"@semantic-release/git"
]
}
}

209

test/test.js

@@ -0,1 +1,2 @@

// @ts-check
'use strict'

@@ -7,9 +8,35 @@

const path = require('path')
const BufferList = require('../')
const os = require('os')
const BufferListStream = require('../')
const { Buffer } = require('buffer')
const encodings =
('hex utf8 utf-8 ascii binary base64' +
(process.browser ? '' : ' ucs2 ucs-2 utf16le utf-16le')).split(' ')
/**
* This typedef allows us to add _bufs to the API without declaring it publicly on types.
* @typedef { BufferListStream & { _bufs?: Buffer[] }} BufferListStreamWithPrivate
*/
/**
* Just for typechecking in js
* @type { NodeJS.Process & { browser?: boolean }}
*/
const process = globalThis.process
/** @type {BufferEncoding[]} */
const encodings = ['ascii', 'utf8', 'utf-8', 'hex', 'binary', 'base64']
if (process.browser) {
encodings.push(
'ucs2',
'ucs-2',
'utf16le',
/**
* This alias is not in typescript typings for BufferEncoding. Still have to fix
* @see https://nodejs.org/api/buffer.html#buffers-and-character-encodings
*/
// @ts-ignore
'utf-16le'
)
}
require('./indexOf')

@@ -20,3 +47,3 @@ require('./isBufferList')

tape('single bytes from single buffer', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()

@@ -37,3 +64,3 @@ bl.append(Buffer.from('abcd'))

tape('single bytes from multiple buffers', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()

@@ -62,3 +89,3 @@ bl.append(Buffer.from('abcd'))

tape('multi bytes from single buffer', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()

@@ -78,3 +105,3 @@ bl.append(Buffer.from('abcd'))

tape('multi bytes from single buffer (negative indexes)', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()

@@ -93,3 +120,3 @@ bl.append(Buffer.from('buffer'))

tape('multiple bytes from multiple buffers', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()

@@ -114,6 +141,6 @@ bl.append(Buffer.from('abcd'))

tape('multiple bytes from multiple buffer lists', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()
bl.append(new BufferList([Buffer.from('abcd'), Buffer.from('efg')]))
bl.append(new BufferList([Buffer.from('hi'), Buffer.from('j')]))
bl.append(new BufferListStream([Buffer.from('abcd'), Buffer.from('efg')]))
bl.append(new BufferListStream([Buffer.from('hi'), Buffer.from('j')]))

@@ -134,13 +161,15 @@ t.equal(bl.length, 10)

tape('multiple bytes from crazy nested buffer lists', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()
bl.append(new BufferList([
new BufferList([
new BufferList(Buffer.from('abc')),
Buffer.from('d'),
new BufferList(Buffer.from('efg'))
]),
new BufferList([Buffer.from('hi')]),
new BufferList(Buffer.from('j'))
]))
bl.append(
new BufferListStream([
new BufferListStream([
new BufferListStream(Buffer.from('abc')),
Buffer.from('d'),
new BufferListStream(Buffer.from('efg'))
]),
new BufferListStream([Buffer.from('hi')]),
new BufferListStream(Buffer.from('j'))
])
)

@@ -160,3 +189,3 @@ t.equal(bl.length, 10)

tape('append accepts arrays of Buffers', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()

@@ -174,3 +203,3 @@ bl.append(Buffer.from('abc'))

tape('append accepts arrays of Uint8Arrays', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()

@@ -188,8 +217,13 @@ bl.append(new Uint8Array([97, 98, 99]))

tape('append accepts arrays of BufferLists', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()
bl.append(Buffer.from('abc'))
bl.append([new BufferList('def')])
bl.append(new BufferList([Buffer.from('ghi'), new BufferList('jkl')]))
bl.append([Buffer.from('mnop'), new BufferList([Buffer.from('qrstu'), Buffer.from('vwxyz')])])
bl.append([new BufferListStream('def')])
bl.append(
new BufferListStream([Buffer.from('ghi'), new BufferListStream('jkl')])
)
bl.append([
Buffer.from('mnop'),
new BufferListStream([Buffer.from('qrstu'), Buffer.from('vwxyz')])
])
t.equal(bl.length, 26)

@@ -202,8 +236,8 @@ t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')

tape('append chainable', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()
t.ok(bl.append(Buffer.from('abcd')) === bl)
t.ok(bl.append([Buffer.from('abcd')]) === bl)
t.ok(bl.append(new BufferList(Buffer.from('abcd'))) === bl)
t.ok(bl.append([new BufferList(Buffer.from('abcd'))]) === bl)
t.ok(bl.append(new BufferListStream(Buffer.from('abcd'))) === bl)
t.ok(bl.append([new BufferListStream(Buffer.from('abcd'))]) === bl)

@@ -214,6 +248,11 @@ t.end()

tape('append chainable (test results)', function (t) {
const bl = new BufferList('abc')
.append([new BufferList('def')])
.append(new BufferList([Buffer.from('ghi'), new BufferList('jkl')]))
.append([Buffer.from('mnop'), new BufferList([Buffer.from('qrstu'), Buffer.from('vwxyz')])])
const bl = new BufferListStream('abc')
.append([new BufferListStream('def')])
.append(
new BufferListStream([Buffer.from('ghi'), new BufferListStream('jkl')])
)
.append([
Buffer.from('mnop'),
new BufferListStream([Buffer.from('qrstu'), Buffer.from('vwxyz')])
])

@@ -227,3 +266,3 @@ t.equal(bl.length, 26)

tape('consuming from multiple buffers', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()

@@ -263,3 +302,4 @@ bl.append(Buffer.from('abcd'))

tape('complete consumption', function (t) {
const bl = new BufferList()
/** @type {BufferListStreamWithPrivate} */
const bl = new BufferListStream()

@@ -281,3 +321,3 @@ bl.append(Buffer.from('a'))

const buf3 = Buffer.alloc(3)
const bl = new BufferList()
const bl = new BufferListStream()

@@ -311,3 +351,3 @@ buf1[0] = 0x1

const buf3 = Buffer.alloc(3)
const bl = new BufferList()
const bl = new BufferListStream()

@@ -346,3 +386,3 @@ buf1[0] = 0x1

const buf3 = Buffer.alloc(3)
const bl = new BufferList()
const bl = new BufferListStream()

@@ -373,3 +413,3 @@ buf1[0] = 0x1

const buf3 = Buffer.alloc(3)
const bl = new BufferList()
const bl = new BufferListStream()

@@ -419,3 +459,3 @@ buf2[0] = 0x2

const buf3 = Buffer.alloc(3)
const bl = new BufferList()
const bl = new BufferListStream()

@@ -445,3 +485,3 @@ buf1[0] = 0x01

const buf3 = Buffer.alloc(10)
const bl = new BufferList()
const bl = new BufferListStream()

@@ -472,3 +512,3 @@ buf1[0] = 0x01

tape('test toString', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()

@@ -490,3 +530,3 @@ bl.append(Buffer.from('abcd'))

tape('test toString encoding', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()
const b = Buffer.from('abcdefghij\xff\x00')

@@ -511,3 +551,3 @@

const clone = Buffer.from(secret)
const bl = new BufferList()
const bl = new BufferListStream()
bl.append(Buffer.from('a'))

@@ -527,3 +567,3 @@ bl.consume(-1024)

const bl = new BufferList((err, buf) => {
const bl = new BufferListStream((err, buf) => {
t.ok(Buffer.isBuffer(buf))

@@ -534,7 +574,7 @@ t.ok(err === null)

bl.pipe(fs.createWriteStream('/tmp/bl_test_rnd_out.dat'))
bl.pipe(fs.createWriteStream(path.join(os.tmpdir(), 'bl_test_rnd_out.dat')))
.on('close', function () {
const rndhash = crypto.createHash('md5').update(random).digest('hex')
const md5sum = crypto.createHash('md5')
const s = fs.createReadStream('/tmp/bl_test_rnd_out.dat')
const s = fs.createReadStream(path.join(os.tmpdir(), 'bl_test_rnd_out.dat'))

@@ -549,4 +589,4 @@ s.on('data', md5sum.update.bind(md5sum))

fs.writeFileSync('/tmp/bl_test_rnd.dat', random)
fs.createReadStream('/tmp/bl_test_rnd.dat').pipe(bl)
fs.writeFileSync(path.join(os.tmpdir(), 'bl_test_rnd.dat'), random)
fs.createReadStream(path.join(os.tmpdir(), 'bl_test_rnd.dat')).pipe(bl)
})

@@ -557,6 +597,6 @@

const buf2 = crypto.randomBytes(1024)
let b = BufferList(buf)
let b = BufferListStream(buf)
t.equal(buf.toString('hex'), b.slice().toString('hex'), 'same buffer')
b = BufferList([buf, buf2])
b = BufferListStream([buf, buf2])
t.equal(b.slice().toString('hex'), Buffer.concat([buf, buf2]).toString('hex'), 'same buffer')

@@ -568,3 +608,3 @@

tape('test String appendage', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()
const b = Buffer.from('abcdefghij\xff\x00')

@@ -586,3 +626,3 @@

tape('test Number appendage', function (t) {
const bl = new BufferList()
const bl = new BufferListStream()
const b = Buffer.from('1234567890')

@@ -604,3 +644,3 @@

t.plan(3)
BufferList(function (err, data) {
BufferListStream(function (err, data) {
t.notOk(err, 'no error')

@@ -619,3 +659,3 @@ t.ok(Buffer.isBuffer(data), 'got a buffer')

const exp = inp1 + ' and ' + inp2
const bl = BufferList()
const bl = BufferListStream()

@@ -630,4 +670,4 @@ bl.write(inp1)

tape('should emit finish', function (t) {
const source = BufferList()
const dest = BufferList()
const source = BufferListStream()
const dest = BufferListStream()

@@ -646,3 +686,3 @@ source.write('hello')

const buf2 = Buffer.alloc(1024)
const b = BufferList(buf)
const b = BufferListStream(buf)

@@ -658,3 +698,3 @@ b.copy(buf2)

const buf2 = Buffer.alloc(1024)
const b = BufferList(buf)
const b = BufferListStream(buf)

@@ -671,3 +711,3 @@ b.append(buf)

const buf2 = Buffer.alloc(1024)
const b = BufferList(buf)
const b = BufferListStream(buf)

@@ -683,3 +723,3 @@ b.copy(buf2, 20)

const buf2 = Buffer.alloc(5)
const b = BufferList(buf)
const b = BufferListStream(buf)

@@ -694,3 +734,3 @@ b.copy(buf2, 0, 5)

const rnd = crypto.randomBytes(10)
const b = BufferList(rnd) // put the random bytes there
const b = BufferListStream(rnd) // put the random bytes there
const actual = Buffer.alloc(3)

@@ -710,3 +750,3 @@ const expected = Buffer.alloc(3)

const buf2 = Buffer.alloc(10)
const b = BufferList(buf)
const b = BufferListStream(buf)

@@ -722,3 +762,3 @@ b.append(buf)

tape('shallow slice across buffer boundaries', function (t) {
const bl = new BufferList(['First', 'Second', 'Third'])
const bl = new BufferListStream(['First', 'Second', 'Third'])

@@ -733,3 +773,3 @@ t.equal(bl.shallowSlice(3, 13).toString(), 'stSecondTh')

const bl = new BufferList(['First', 'Second', 'Third'])
const bl = new BufferListStream(['First', 'Second', 'Third'])

@@ -745,3 +785,3 @@ t.equal(bl.shallowSlice(5, 10).toString(), 'Secon')

const bl = new BufferList(['First', 'Second', 'Third'])
const bl = new BufferListStream(['First', 'Second', 'Third'])

@@ -756,3 +796,3 @@ t.equal(bl.shallowSlice(0, 5).toString(), 'First')

const bl = new BufferList(['First', 'Second', 'Third'])
const bl = new BufferListStream(['First', 'Second', 'Third'])

@@ -769,3 +809,3 @@ t.equal(bl.shallowSlice().toString(), 'FirstSecondThird')

const buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
const bl = (new BufferList(buffers)).shallowSlice(5, -3)
const bl = new BufferListStream(buffers).shallowSlice(5, -3)

@@ -782,3 +822,3 @@ buffers[1].fill('h')

const buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
const bl = (new BufferList(buffers)).shallowSlice(0, 0)
const bl = (new BufferListStream(buffers)).shallowSlice(0, 0)

@@ -792,3 +832,3 @@ t.equal(bl.length, 0)

const buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
const bl = (new BufferList(buffers)).shallowSlice(10, 10)
const bl = (new BufferListStream(buffers)).shallowSlice(10, 10)

@@ -801,3 +841,3 @@ t.equal(bl.length, 0)

const bl = new BufferList('abcdefghij\xff\x00')
const bl = new BufferListStream('abcdefghij\xff\x00')
const dup = bl.duplicate()

@@ -812,3 +852,4 @@

const bl = new BufferList('alsdkfja;lsdkfja;lsdk')
/** @type {BufferListStreamWithPrivate} */
const bl = new BufferListStream('alsdkfja;lsdkfja;lsdk')

@@ -824,3 +865,4 @@ bl.destroy()

const bl = new BufferList('alsdkfja;lsdkfja;lsdk')
/** @type {BufferListStreamWithPrivate} */
const bl = new BufferListStream('alsdkfja;lsdkfja;lsdk')
const err = new Error('kaboom')

@@ -840,3 +882,4 @@

const bl = new BufferList()
/** @type {BufferListStreamWithPrivate} */
const bl = new BufferListStream()
fs.createReadStream(path.join(__dirname, '/test.js'))

@@ -854,3 +897,4 @@ .pipe(bl)

const bl = new BufferList()
/** @type {BufferListStreamWithPrivate} */
const bl = new BufferListStream()

@@ -872,4 +916,4 @@ fs.createReadStream(path.join(__dirname, '/test.js'))

const bl = new BufferList()
/** @type {BufferListStreamWithPrivate} */
const bl = new BufferListStream()
fs.createReadStream(path.join(__dirname, '/test.js'))

@@ -890,4 +934,5 @@ .on('end', onEnd)

const bl = new BufferList()
const ds = new BufferList()
/** @type {BufferListStreamWithPrivate} */
const bl = new BufferListStream()
const ds = new BufferListStream()

@@ -918,3 +963,3 @@ fs.createReadStream(path.join(__dirname, '/test.js'))

fs.createReadStream('/does/not/exist').pipe(BufferList(function (err, data) {
fs.createReadStream('/does/not/exist').pipe(BufferListStream(function (err, data) {
t.ok(err instanceof Error, 'has error')

@@ -921,0 +966,0 @@ t.notOk(data, 'no data')

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