How to use the get-stream.buffer function in get-stream

To help you get started, we’ve selected a few get-stream examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github npm / pacote / test / file.tarball.js View on Github external
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')
github npm / pacote / test / registry.tarball.js View on Github external
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')
    })
  })
})
github grantila / fetch-h2 / dist / lib / body.js View on Github external
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() {
github npm / pacote / tarball.js View on Github external
  return withTarballStream(spec, opts, stream => getStream.buffer(stream))
}
github sindresorhus / execa / lib / stream.js View on Github external
const getStreamPromise = (stream, {encoding, buffer, maxBuffer}) => {
	if (!stream || !buffer) {
		return;
	}

	if (encoding) {
		return getStream(stream, {encoding, maxBuffer});
	}

	return getStream.buffer(stream, {maxBuffer});
};
github piranna / fs-fuse / index.js View on Github external
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))
  }
github android-js / androidjs-builder / example / helloworld / node_modules / cacheable-request / src / index.js View on Github external
(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,
github grantila / fetch-h2 / dist / lib / body.js View on Github external
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() {
github lukechilds / cacheable-request / src / index.js View on Github external
(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,
github sindresorhus / gulp-zip / index.js View on Github external
(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();
		})();

get-stream

Get a stream as a string, Buffer, ArrayBuffer or array

MIT
Latest version published 1 month ago

Package Health Score

89 / 100
Full package analysis

Popular get-stream functions