Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return checkedCall(callback => {
// |tmp.file| checks arguments length to detect options rather than doing a
// truthy check, so we must only pass options if there are some to pass.
if (opt_options) {
tmp.file(opt_options, callback);
} else {
tmp.file(callback);
}
});
};
function downloadItem(item, callback) {
var options = {
BucketName : argv.bucket,
ObjectName : item.Key,
};
fmt.field('Downloading', item.Key);
tmp.file({ template : '/tmp/tmp-XXXXXXXX.' + process.pid }, function(err, tmpfile, fd) {
if ( err ) {
fmt.field('TmpFileError', err);
callback();
return;
}
// now download the item
s3.GetObject(options, function(err, data) {
if (err) {
fmt.field('ErrorDownloading', err);
callback();
return;
}
fs.write(fd, data.Body, 0, data.Body.length, 0, function(err, written, buffer) {
if ( err ) {
new Promise((resolve, reject) => {
require('tmp').file({ prefix: 'shell-', postfix }, (err, filepath) => {
if (err) {
console.error(err)
reject(err)
} else {
resolve(filepath)
}
})
})
const write = source =>
return new Promise((resolve, reject) => {
tmp.file(options, (err, tmpFile, fd, cleanupCallback) => {
if (err) {
return reject(err);
}
resolve({ filePath: tmpFile, cleanupCallback: cleanupCallback });
});
});
}
return new Promise((resolve, reject) => {
tmp.file(opts || {}, (err, path, fd, cleanup) => {
if (err) return reject(err)
resolve({path, fd, cleanup})
})
})
}
if (process.platform !== 'win32' && (file.stat.mode & 0o100))
{
node.executable = true;
}
this.offset.add(long(size));
return callback();
};
const tr = options.transform && options.transform(p);
if (tr)
{
return tmp.file((err: any, newPath: string) => {
if (err)
{
return handler();
}
const out = fs.createWriteStream(newPath);
const stream = fs.createReadStream(p);
stream.pipe(tr).pipe(out);
return out.on('close', () => {
fs.lstat(newPath, (lstatErr: any, stat: fs.Stats) => {
if (lstatErr)
{
throw new Error(lstatErr);
}
Util.createTempFile = function (fileExtension, callback) {
Tmp.file({postfix: "." + fileExtension}, callback);
};
private async createTmpFile(rspExists: boolean, rspId: string, content: Protocol.GetServerJsonResponse): Promise {
return tmp.file({ prefix: `${this.PREFIX_TMP}-${content.serverHandle.id}-` , postfix: '.json' }, (err, path) => {
if (err) {
return Promise.reject('Could not handle server response. Unable to create temp file');
}
if (rspExists) {
this.RSPServerProperties.get(rspId).push({ server: content.serverHandle.id, file: path});
} else {
this.RSPServerProperties.set(rspId, [{ server: content.serverHandle.id, file: path}]);
}
this.saveAndShowEditor(path, content.serverJson);
});
}
function createZip(filepaths: string[], callback: IZipCallback): void {
tmp.file({ keep : true, postfix : '.zip' }, (err, zipfilename) => {
if (err) {
log('Failure to create zip file', err, filepaths);
return callback(err);
}
const outputStream = fs.createWriteStream(zipfilename);
const archive = archiver('zip', { zlib : { level : 9 } });
outputStream.on('close', () => {
callback(undefined, zipfilename, archive.pointer());
});
outputStream.on('warning', (warning) => {
log('Unexpected warning event from writable filestream', warning);
});
return new Promise((resolve, reject) => {
tmp.file({ prefix: 'vscode-restclient-', postfix: ".http" }, function _tempFileCreated(err, tmpFilePath, fd) {
if (err) {
reject(err);
return;
}
let output = `${request.method.toUpperCase()} ${request.url}${EOL}`;
if (request.headers) {
for (const header in request.headers) {
if (request.headers.hasOwnProperty(header)) {
const value = request.headers[header];
output += `${header}: ${value}${EOL}`;
}
}
}
if (request.body) {
output += `${EOL}${request.body}`;
}