Comparing version 0.1.0 to 0.1.1
14
index.js
@@ -16,1 +16,15 @@ 'use strict' | ||
} | ||
module.exports.toBuffer = module.exports | ||
module.exports.toList = async function * (source) { | ||
for await (const b of source) { | ||
if (Buffer.isBuffer(b)) { | ||
yield new BufferList().append(b) | ||
} else if (BufferList.isBufferList(b)) { | ||
yield b | ||
} else { | ||
yield new BufferList().append(Buffer.from(b)) | ||
} | ||
} | ||
} |
{ | ||
"name": "it-buffer", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Is it a string? Is it a BufferList? Or just a Buffer? Worry no more with `it-buffer`!", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,1 +18,3 @@ # it-buffer | ||
``` | ||
Also exposes `.toBuffer()` (the same as above) and `.toList()` (returns BufferLists instead of Buffers) |
34
test.js
@@ -14,3 +14,3 @@ 'use strict' | ||
const res = await pipe( | ||
async function * () { | ||
function * () { | ||
yield input | ||
@@ -26,2 +26,16 @@ }, | ||
const t2 = (name, input, output) => { | ||
it(name, async () => { | ||
const res = await pipe( | ||
function * () { | ||
yield input | ||
}, | ||
toBuffer.toList, | ||
collect | ||
) | ||
assert.deepEqual(res, [output], 'invalid data returned') | ||
}) | ||
} | ||
describe('it-buffer', () => { | ||
@@ -45,2 +59,20 @@ t( | ||
) | ||
t2( | ||
'string', | ||
'hello', | ||
new BufferList().append(Buffer.from('hello')) | ||
) | ||
t2( | ||
'buffer', | ||
Buffer.from('hi'), | ||
new BufferList().append(Buffer.from('hi')) | ||
) | ||
t2( | ||
'buffer-list', | ||
new BufferList().append(Buffer.from('hello')).append(Buffer.from('world')), | ||
new BufferList().append(Buffer.from('hello')).append(Buffer.from('world')) | ||
) | ||
}) |
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
3220
88
20