Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should error if the stream is a Transform', function(done) {
var chan = outSession.WriteChannel();
var bin = new Transform();
outSession.once('error', function(err) {
expect(err.message).to.eql('unable to auto-serialize a Transform stream not in object mode');
done();
outSession.on('error', function() {});
});
chan.end({
bin: bin
});
inSession.on('channel', function server(chan) {
chan.resume(); // skip all of it
});
});
function append (text) {
return Transform({
write (chunk, enc, cb) {
this.push(chunk)
cb()
},
flush (cb) {
this.push('\n' + text)
cb()
}
})
}
function handleGet (req, res) {
const split = req.url.split('?')
const key = split[0]
const query = querystring.parse(split[1])
if (query.live) {
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive'
})
var transform = new Transform({
objectMode: true,
transform (chunk, enc, cb) {
this.push('data:' + JSON.stringify(chunk.value) + '\n\n')
cb()
}
})
pump(db.liveUpdates(key), transform, res)
} else {
db.get(key, function (err, data) {
if (err) {
res.statusCode = 500
res.end(err.message)
return
}
if (!data) {
private createPrettyTransport(level: string, prettyOptions?: PrettyOptions): Transform {
const pinoPretty = PinoPretty({
...{
levelFirst: false,
translateTime: "yyyy-mm-dd HH:MM:ss.l",
},
...prettyOptions,
});
const levelValue = this.logger.levels.values[level];
return new Transform({
transform(chunk, enc, cb) {
try {
const json = JSON.parse(chunk);
if (json.level >= levelValue) {
const line = pinoPretty(json);
if (line !== undefined) {
return cb(null, line);
}
}
} catch (ex) {
//
}
return cb();
},
});
module.exports = function(){
var reader = new stream.Transform();
reader.algorithm = 'sha1';
reader.count = 0;
reader.isTTY = false;
reader.reset = function(){
this.count = 0;
this.set.clear();
this.started = false;
};
reader.process = function(element){
var hash = crypto
.createHash(this.algorithm || 'sha1')
function buildProxy () {
var proxy = new Transform()
proxy._write = function (chunk, encoding, next) {
socketTask.send({
data: chunk.buffer,
success: function () {
next()
},
fail: function (errMsg) {
next(new Error(errMsg))
}
})
}
proxy._flush = function socketEnd (done) {
socketTask.close({
success: function () {
done()
}
function onresponse(res) {
res
.resume()
.on('error', bail)
.pipe(csv({delimiter: '\t', objectMode: true}))
.pipe(new Transform({objectMode: true, transform: onrow}))
.pipe(join(',\n'))
.pipe(wrap('{\n', '\n}\n'))
.pipe(fs.createWriteStream('index.json'))
}
return (opts) => {
opts = opts || {}
const pt = new Stream.Transform({
objectMode: true,
transform (chunk, encoding, cb) {
cb(null, transformChunk(chunk))
}
})
send({
path: 'stats/bw',
qs: opts
}, (err, stream) => {
if (err) {
return pt.destroy(err)
}
pump(stream, pt)
})
return (args, opts) => {
opts = opts || {}
const transform = new Transform({
objectMode: true,
transform (entry, encoding, callback) {
callback(null, toEntry(entry))
}
})
const output = new PassThrough({
objectMode: true
})
send({
path: 'files/ls',
args: args,
qs: Object.assign({}, opts, { stream: true })
}, (err, res) => {
module.exports = function (options) {
var t = new Transform({
objectMode: true,
//transform: ...
})
//should reformat after readable-stream support simplified constructor api
t._transform = function (file, enc, next) {
if (file.isBuffer()) {
file.contents = less(file.contents, options)
} else if (file.isStream()) {
file.contents.on('error', this.emit.bind(this, 'error'))
file.contents = less(file.contents, options)
}
this.push(file)
return next()
}