@saulx/utils
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -5,16 +5,3 @@ "use strict"; | ||
exports.default = (stream) => new Promise((resolve, reject) => { | ||
let pipit = false; | ||
let s = stream; | ||
if (stream instanceof stream_1.Readable || stream instanceof stream_1.PassThrough) { | ||
s = stream; | ||
} | ||
else if (stream instanceof stream_1.Writable || stream instanceof stream_1.Duplex) { | ||
s = new stream_1.PassThrough(); | ||
pipit = true; | ||
} | ||
else { | ||
console.warn('not an instance of stream - trying writable'); | ||
// @ts-ignore | ||
s = new stream_1.PassThrough(stream); | ||
} | ||
const s = new stream_1.PassThrough(); | ||
s.on('error', err => { | ||
@@ -25,12 +12,15 @@ reject(err); | ||
s.on('data', s => { | ||
buffers.push(s); | ||
if (typeof s === 'string') { | ||
buffers.push(Buffer.from(s)); | ||
} | ||
else { | ||
buffers.push(s); | ||
} | ||
}); | ||
s.on('end', () => { | ||
resolve(Buffer.from(buffers)); | ||
s.on('end', x => { | ||
resolve(Buffer.concat(buffers)); | ||
}); | ||
if (pipit) { | ||
// @ts-ignore | ||
stream.pipe(s); | ||
} | ||
// @ts-ignore | ||
stream.pipe(s); | ||
}); | ||
//# sourceMappingURL=readStream.js.map |
{ | ||
"name": "@saulx/utils", | ||
"main": "./dist/index.js", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"scripts": { | ||
@@ -6,0 +6,0 @@ "build": "tsc", |
@@ -1,17 +0,6 @@ | ||
import { Stream, Readable, PassThrough, Writable, Duplex } from 'stream' | ||
import { Stream, PassThrough } from 'stream' | ||
export default (stream: Stream): Promise<Buffer> => | ||
new Promise((resolve, reject) => { | ||
let pipit = false | ||
let s = stream | ||
if (stream instanceof Readable || stream instanceof PassThrough) { | ||
s = stream | ||
} else if (stream instanceof Writable || stream instanceof Duplex) { | ||
s = new PassThrough() | ||
pipit = true | ||
} else { | ||
console.warn('not an instance of stream - trying writable') | ||
// @ts-ignore | ||
s = new PassThrough(stream) | ||
} | ||
const s = new PassThrough() | ||
s.on('error', err => { | ||
@@ -22,12 +11,13 @@ reject(err) | ||
s.on('data', s => { | ||
buffers.push(s) | ||
if (typeof s === 'string') { | ||
buffers.push(Buffer.from(s)) | ||
} else { | ||
buffers.push(s) | ||
} | ||
}) | ||
s.on('end', () => { | ||
resolve(Buffer.from(buffers)) | ||
s.on('end', x => { | ||
resolve(Buffer.concat(buffers)) | ||
}) | ||
if (pipit) { | ||
// @ts-ignore | ||
stream.pipe(s) | ||
} | ||
// @ts-ignore | ||
stream.pipe(s) | ||
}) |
@@ -607,8 +607,10 @@ import test from 'ava' | ||
const { PassThrough } = require('stream') | ||
const pass = new PassThrough() | ||
pass.write('ok') // Will not emit 'data'. | ||
readStream(pass).then(v => { | ||
const { createReadStream } = require('fs') | ||
const { join } = require('path') | ||
readStream(createReadStream(join(__dirname, '../package.json'))).then(v => { | ||
const pkg = JSON.parse(v.toString()) | ||
t.is(pkg.name, '@saulx/utils') | ||
t.end() | ||
}) | ||
pass.end(Buffer.from('flap')) | ||
}) |
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
64854
1605