Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return fs.writeFileAsync(tarballPath, tarData).then(() => {
return getBuff(fetch.tarball(npa(tarballPath), OPTS))
}).then(data => {
t.deepEqual(data, tarData, 'fetched tarball data matches one from local')
return mockTar(pkg).then(tarData => {
const srv = tnock(t, OPTS.registry)
srv.get('/foo').reply(200, META(tarData))
srv.get('/foo/-/foo-1.2.3.tgz').reply(404)
return getBuff(fetch.tarball(npa('foo@^1.2.3'), OPTS)).then(data => {
throw new Error('this was not supposed to succeed ' + data.length + data.toString('utf8'))
}).catch(err => {
t.ok(err, 'correctly errored')
t.notMatch(err.message, /not supposed to succeed/)
t.equal(err.code, 'E404', 'got a 404 back')
})
})
})
async arrayBuffer(allowIncomplete = false) {
this._ensureUnused();
if (this._body == null)
return this.validateIntegrity(emptyBuffer, allowIncomplete);
else if (isStream(this._body))
return get_stream_1.buffer(this._body)
.then(buffer => this.validateIntegrity(buffer, allowIncomplete))
.then(buffer => toArrayBuffer(buffer));
else if (isBuffer(this._body))
return this.validateIntegrity(toArrayBuffer(this._body), allowIncomplete);
else
throwUnknownData();
}
async blob() {
return withTarballStream(spec, opts, stream => getStream.buffer(stream))
}
const getStreamPromise = (stream, {encoding, buffer, maxBuffer}) => {
if (!stream || !buffer) {
return;
}
if (encoding) {
return getStream(stream, {encoding, maxBuffer});
}
return getStream.buffer(stream, {maxBuffer});
};
this.read = function(path, fd, buffer, length, position, cb)
{
if(fs.read)
return fs.read(fd, buffer, 0, length, position, fsCallback.bind(cb))
if(!fs.createReadStream) return cb(ENOSYS)
const options = {start: position, end: position+length}
getStream(fs.createReadStream(path, options), {maxBuffer: length})
.then(function(data)
{
data.copy(buffer)
cb(null, data.length)
}, fsCallback.bind(cb))
}
(async () => {
try {
const bodyPromise = getStream.buffer(response);
await Promise.race([
requestErrorPromise,
new Promise(resolve => response.once('end', resolve))
]);
if (requestErrored) {
return;
}
const body = await bodyPromise;
const value = {
cachePolicy: response.cachePolicy.toObject(),
url: response.url,
statusCode: response.fromCache ? revalidate.statusCode : response.statusCode,
async text(allowIncomplete = false) {
this._ensureUnused();
if (this._body == null)
return Promise.resolve(this.validateIntegrity(emptyBuffer, allowIncomplete))
.then(() => this._body);
else if (isStream(this._body))
return get_stream_1.buffer(this._body)
.then(already_1.tap(buffer => this.validateIntegrity(buffer, allowIncomplete)))
.then(buffer => buffer.toString());
else if (isBuffer(this._body))
return Promise.resolve(this._body)
.then(already_1.tap(buffer => this.validateIntegrity(buffer, allowIncomplete)))
.then(buffer => buffer.toString());
else
return throwUnknownData();
}
async readable() {
(async () => {
try {
const bodyPromise = getStream.buffer(response);
await Promise.race([
requestErrorPromise,
new Promise(resolve => response.once('end', resolve))
]);
if (requestErrored) {
return;
}
const body = await bodyPromise;
const value = {
cachePolicy: response.cachePolicy.toObject(),
url: response.url,
statusCode: response.fromCache ? revalidate.statusCode : response.statusCode,
(async () => {
const data = await getStream.buffer(zip.outputStream);
this.push(new Vinyl({
cwd: firstFile.cwd,
base: firstFile.base,
path: path.join(firstFile.base, filename),
contents: data
}));
callback();
})();