Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
MultiPartUpload.prototype._uploadPart = function(part, callback) {
// If we haven't started the upload yet, wait for the initialization
if (!this.uploadId) {
return this.on('initiated', this._uploadPart.bind(this, part, callback));
}
var url = this.objectName + '?partNumber=' + part.id + '&uploadId=' + this.uploadId,
headers = { 'Content-Length': part.length },
req = this.client.request('PUT', url, headers),
partStream = !this.noDisk && fs.createReadStream(part.fileName, {start: part.offset, end: part.offset + part.length - 1}),
mpu = this,
written = 0;
// Wait for the upload to complete
req.on('response', function(res) {
if (res.statusCode != 200) {
var result = {part: part.id, message: 'Upload failed with status code '+res.statusCode };
mpu.emit('failed', result);
if (--part.triesLeft)
return MultiPartUpload.prototype._uploadPart.call(mpu, part, callback);
else
return callback(result);
}
// Grab the etag and return it
var etag = res.headers.etag,
async function readTestFiles() {
// Read all the HTML test cases into memory.
let htmls = [];
for (const testFile of testFiles) {
console.log(`Opening ${testFile}...`);
let pending = '';
for await (const chunk of fs.createReadStream(testFile, {encoding: 'utf8'})) {
pending += chunk;
let pastLastMarker = 0; // Position just past the previously found marker.
let marker; // Position of the current marker.
while (marker = pending.indexOf(markerText, pastLastMarker), marker !== -1) {
if (marker > pastLastMarker)
htmls.push(pending.substring(pastLastMarker, marker));
pastLastMarker = marker + markerText.length;
}
pending = pending.substring(pastLastMarker);
}
htmls.push(pending);
}
// Parse the URL from each test case.
htmls.forEach((html, i) => {
let newline = html.indexOf('\n');
let compareTextListAgainstFilterFile = (filterFilePath, textList, callback = () => {}) => {
logger.debug('compareTextListAgainstFilterFile')
// Initialize filter entry list
let filterEntryList = []
// Initialize filter file reader
const reader = readline.createInterface({
input: fs.createReadStream(filterFilePath)
})
// Filter file reader: read next line
reader.on('line', (line) => {
logger.debug('compareTextListAgainstFilterFile', 'readline#line')
// Only add filter entry if it's not comment (starting with "//")
if (!line.startsWith(notificationFilterCommentTag)) {
filterEntryList.push(line)
}
})
// Filter file reader: error
reader.on('error', (error) => {
logger.error('compareTextListAgainstFilterFile', 'reader', error)
function pipeStream(dst) {
var readStream = fs.createReadStream(config.inputFile);
readStream.on('open', function () {
readStream.pipe(dst, { end: false });
});
readStream.on('end', function() {
pipeStream(dst);
})
readStream.on('error', function() {
console.log("Unable to open input file for reading.");
process.exit(1);
})
}
'/content-download': function() {
var readPath = path.resolve('./tests/data/metro-armrest.png');
var readStream = fs.createReadStream(readPath);
res.writeHead(200, { 'Content-Type': 'image/png' });
readStream.pipe(res);
},
#!/usr/bin/env node
var fs = require("fs");
var argv = require('minimist')(process.argv.slice(2),{
alias: { h: 'help', t: 'token', l: 'language' }
});
var codewars = require("../");
if (argv.help){
fs.createReadStream(__dirname + '/usage.txt').pipe(process.stdout);
return;
}
argv.language = argv.language || "javascript";
argv.language = argv.language.toLowerCase();
var command = argv._[0];
if (command === "setup"){
if (!argv.token) {
console.log("setup failed, missing required argument: token")
process.exit(0);
}
if (!/javascript|ruby/.test(argv.language)){
console.log("setup failed, unsupported language: " + argv.language);
}
codewars().setup();
function handler (req, res) {
var parsedUrl = url.parse(req.url,true);
console.log("Received req = " + req.method + " " + parsedUrl.pathname) ;
if (req.method === 'POST') {
console.log("POST Request Received");
if(parsedUrl.pathname === '/signup')
{
fs.createReadStream('table.html').pipe(res);
}
else if(parsedUrl.pathname === '/discover')
{
console.log("discovery:: type " + discoverResourceType);
}
else if (parsedUrl.pathname === '/getremoteattr')
{
console.log("/getremoteattr, getremoteattr request:: ");
var body = '';
req.on('data', function(data){ body += data;});
//request data is json
req.on('end', function(){
var json = JSON.parse(body);
Shard.prototype.writeToNodeFromFile = function(id, path, size, file, cb) {
var node = this.coordinator.getNode(id),
stream = fs.createReadStream(file),
returned = false,
request;
console.log("uploading " + path + " of size " + size + " to server " + id + " from shard " + this.id);
function callback(error) {
if (returned) {
return;
}
returned = true;
cb(error);
}
request = http.request({
host : node.host,
if (!options.stdout && options.out === undefined) {
console.log(`Either a output file using --out or --stdout must be specified.`);
process.exitCode = -1;
return;
}
if (options.stdout && !options.compressOnly) {
console.log(`Writing to stdout can only be used together with --compressOnly`);
process.exitCode = -1;
return;
}
let input: NodeJS.ReadStream | fs.ReadStream = process.stdin;
if (options.in !== undefined && fs.existsSync(options.in)) {
input = fs.createReadStream(options.in, { encoding: 'utf8'});
}
let db: graph.GraphStore | blob.BlobStore | undefined;
if (options.compressOnly && options.out) {
writer = new FileWriter(fs.openSync(options.out, 'w'));
} else if (!options.compressOnly && options.out) {
let filename = options.out;
if (!filename.endsWith('.db')) {
filename = filename + '.db';
}
if (options.format === 'blob') {
if (options.projectVersion === undefined) {
console.log(`Blob format requires a project version.`);
process.exitCode = -1;
return;
}
db = new blob.BlobStore(filename, options.projectVersion, options.delete);
fs.stat (local, function (error, stats){
if (error) return cb (error);
var closed = false;
var rs = fs.createReadStream (local)
.on ("error", function (error){
//Abort the PUT stream
err = error;
ps.abort (tftp.EIO);
})
.on ("close", function (){
closed = true;
});
var ps = new PutStream (remote, me._options, { size: stats.size })
.on ("error", function (error){
if (closed){
//Empty origin file
cb (error);
}else{
//Close the readable stream