Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log('pushing file' + file_path);
if (file_path.match(/\.json$/)) {
results = JSON.parse(fs.readFileSync(file_path, "utf-8"));
var ret = {
uri: uri,
method: "PUT",
json: results,
gzip: true
};
} else {
// Create form data
var formData = {
files: []
};
// Add file
formData.files.push(fs.createReadStream(file_path));
var ret = {
uri: uri + "/files",
method: "PUT",
formData: formData,
gzip: true
};
}
filesP.push(rp(ret));
};
if (stats.mtime instanceof Date) res.lastModified = stats.mtime
if (typeof stats.size === 'number') res.length = stats.size
res.type = stats.type || path.extname(stats.pathname)
res.etag = yield this._etag(stats)
res.set('Cache-Control', this._cacheControl)
// do we push dependencies on 304s?
let fresh = req.fresh
if (fresh) return res.status = 304
if (req.method === 'HEAD') return
assert('body' in stats || 'filename' in stats)
res.body = 'body' in stats
? stats.body
: fs.createReadStream(stats.filename)
}
} else {
// rename error
throw err;
}
}
} else {
// clean tmpFile
await fs.unlink(tmpFile);
}
const stat = await fs.stat(tarballFile);
debug('[%s@%s] saved %s %s => %s',
pkg.name, pkg.version, bytes(stat.size), tarballUrl, tarballFile);
options.totalTarballSize += stat.size;
}
const stream = fs.createReadStream(tarballFile);
stream.tarballFile = tarballFile;
return stream;
}
it('should copy a stream', function () {
var out = path.join(build, 'test2.js')
return cp(fs.createReadStream(__filename), out).then(function (_out) {
assert.equal(out, _out);
return fs.stat(out)
})
})
async function readGeckoRevisionFromIni(iniFile) {
let stream = fs.createReadStream(iniFile, {encoding: 'utf8'});
let line = await findInStream(stream, matchSourceStamp);
return matchSourceStamp(line).split('=')[1];
}
res.etag = file.etag
res.lastModified = file.stats.mtime
res.type = file.type
if (cachecontrol) res.set('Cache-Control', cachecontrol)
if (req.fresh) {
res.status = 304
return file
}
if (method === 'HEAD') return file
if (file.compress && req.acceptsEncodings('gzip', 'identity') === 'gzip') {
res.set('Content-Encoding', 'gzip')
res.length = file.compress.stats.size
res.body = fs.createReadStream(file.compress.path)
} else {
res.set('Content-Encoding', 'identity')
res.length = file.stats.size
res.body = fs.createReadStream(path)
}
return file
}
yield function (done) {
fs.createReadStream(path)
.on('error', done)
.pipe(zlib.createGzip())
.on('error', done)
.pipe(fs.createWriteStream(tmp))
.on('error', done)
.on('finish', done)
}
return new Promise((resolve, reject) => {
readStream = byline(fs.createReadStream(filename))
readStream.on('data', (line) => {
parseTriple(line.toString())
})
readStream.on('finish', () => {
resolve()
})
})
}
registry?: string,
tarball: string,
},
pkgInStoreLocation: string,
lockfileDir: string,
) {
let currentIntegrity!: string
try {
currentIntegrity = (await fs.readFile(path.join(pkgInStoreLocation, TARBALL_INTEGRITY_FILENAME), 'utf8'))
} catch (err) {
return false
}
if (resolution.integrity && currentIntegrity !== resolution.integrity) return false
const tarball = path.join(lockfileDir, resolution.tarball.slice(5))
const tarballStream = fs.createReadStream(tarball)
try {
return Boolean(await ssri.checkStream(tarballStream, currentIntegrity))
} catch (err) {
return false
}
}