Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
apiClients.a.cat('Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq', (err, res) => {
expect(err).to.not.exist
// Do not blow out the memory of nodejs :)
const bigStream = streamifier.createReadStream(testfileBig)
streamEqual(res, bigStream, (err, equal) => {
expect(err).to.not.exist
expect(equal).to.be.true
done()
})
})
})
current.image.getBuffer(mime, function(err, buffer) {
if (that.options.storage == 'local') {
// create a read stream from the buffer and pipe it to the output stream
streamifier.createReadStream(buffer).pipe(current.stream);
}
});
});
let jsonBuffer;
// If a body exists
if (body.length) {
const stableJsonStr = util.normalizeJsonStr(body.toString());
jsonBuffer = new Buffer(stableJsonStr);
req.headers['content-length'] = jsonBuffer.length.toString();
} else {
jsonBuffer = new Buffer(0);
if (req.method !== 'GET') {
req.headers['content-length'] = '0';
}
}
// Stuff the buffer back into the request
// so yakbak can still read the buffer
const readableStream = streamifier.createReadStream(jsonBuffer);
req.on = readableStream.on.bind(readableStream);
return req;
});
};
name: 'SampleDocument.pdf',
ext: 'pdf',
source: {
type: 'path|base64|url',
content: 'string|buffer'
}
}));
}
switch (fileSource.type.toLowerCase()) {
case 'path':
download = fs.createReadStream(fileSource.content);
break;
/* istanbul ignore next */
case 'base64':
download = streamifier.createReadStream(new Buffer(fileSource.content, 'base64'));
break;
/* istanbul ignore next */
case 'url':
download = request({
method: 'GET',
url: fileSource.content,
encoding: null
});
break;
}
download.pause();
parts.push({
headers: {
'Content-Disposition': 'documentId=' + documentId
it('should throw an error', () => {
const source = createReadStream('some source object');
const message = {
text: 'this is a message'
};
return api.uploadImage(userId, source, message).catch(() => {
httpSpy.should.not.have.been.called;
});
});
});
it('should call http', () => {
const fullUrl = `${serviceUrl}/v1/appusers/${userId}/images`;
const source = createReadStream('some source object');
const message = {
text: 'this is a message'
};
return api.uploadImage(userId, source, message).then(() => {
httpSpy.args[0][0].should.eq('POST');
httpSpy.args[0][1].should.eq(fullUrl);
httpSpy.args[0][2].should.be.instanceof(FormData);
httpSpy.args[0][3].should.eql(authHeaders);
});
});
});
it('should call http given access as arg', () => {
const fullUrl = `${serviceUrl}/v1/attachments?access=public`;
const source = createReadStream('some source object');
return api.create('public', source).then(() => {
httpSpy.args[0][0].should.eq('POST');
httpSpy.args[0][1].should.eq(fullUrl);
httpSpy.args[0][2].should.be.instanceof(FormData);
httpSpy.args[0][3].should.eql(authHeaders);
});
});
it('should call http in object mode', () => {
const fullUrl = `${serviceUrl}/v1/attachments?access=public&for=message&userId=userId&appUserId=appUserId`;
const source = createReadStream('some source object');
const params = {
props: {
access: 'public',
for: 'message',
userId: 'userId',
appUserId: 'appUserId'
},
source
};
return api.create(params).then(() => {
httpSpy.args[0][0].should.eq('POST');
httpSpy.args[0][1].should.eq(fullUrl);
httpSpy.args[0][2].should.be.instanceof(FormData);
httpSpy.args[0][3].should.eql(authHeaders);
app.post("/chain", async (req, res) => {
const extractPath = `/tmp/backup${Date.now()}`;
const metadataPath = `${extractPath}/metadata.yml`;
try {
const unTARer = rawTar.extract();
unTARer.on("error", err => {
console.log(err.message);
unTARer.destroy();
res.status(400).send(err.message);
});
const extract = tar.extract(extractPath, { extract: unTARer });
const file = streamifier.createReadStream(req.body);
const stream = file.pipe(extract);
stream.on("finish", async () => {
if (fs.existsSync(metadataPath)) {
const config = loadConfig(metadataPath);
const valid = await verifyHash(config.DirectoryHash, extractPath);
if (valid) {
autostart = false;
await stopMultichain(mcproc);
await moveBackup(multichainDir, extractPath, CHAINNAME);
spawnProcess(() =>
startMultichainDaemon(
CHAINNAME,
externalIpArg,
blockNotifyArg,
P2P_PORT,
multichainDir,
app.get("/__teststream", function(req, res) {
var buf = new Buffer("ahahahaha");
var readStream = Streamifier.createReadStream(buf);
readStream.pipe(res);
});