Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@travetto/base

Package Overview
Dependencies
Maintainers
1
Versions
357
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@travetto/base - npm Package Compare versions

Comparing version 3.2.1 to 3.2.2

2

package.json
{
"name": "@travetto/base",
"version": "3.2.1",
"version": "3.2.2",
"description": "Environment config and common utilities for travetto applications.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -17,2 +17,10 @@ /// <reference types='node' />

interface ReadableStreamReader {
read(): Promise<{ value?: Uint8Array, done?: boolean }>
}
interface ReadableStream {
getReader(): ReadableStreamReader;
}
interface Options {

@@ -57,9 +65,8 @@ writable?: boolean;

blob(): Promise<Blob>;
body: NodeJS.ReadableStream;
formData(): FormData;
body: ReadableStreamReader;
bodyUsed: boolean;
buffer(): Promise<Buffer>;
json(): Promise<any>;
size: number;
text(): Promise<string>;
textConverted(): Promise<string>;
timeout: number;

@@ -66,0 +73,0 @@ }

@@ -9,4 +9,5 @@ import fs from 'fs/promises';

import type { ExecutionState } from './exec';
import type { _Fetch } from './fetch';
type All = Buffer | string | Readable | Uint8Array | NodeJS.ReadableStream;
type All = Buffer | string | Readable | Uint8Array | NodeJS.ReadableStream | _Fetch.ReadableStream;

@@ -19,2 +20,25 @@ /**

/**
* Convert a fetch/ReadableStream into a standard node Readable
* @param src
* @returns
*/
static fetchBodyToStream(src: _Fetch.ReadableStream): Readable {
const reader = src.getReader();
return new Readable({
read(): void {
reader.read().then(({ done, value }) => {
if (value) {
this.push(value);
}
if (done) {
this.emit('end');
}
});
},
emitClose: true
});
}
/**
* Convert buffer to a stream

@@ -33,3 +57,6 @@ * @param src The buffer to stream

*/
static async streamToBuffer(src: Readable | NodeJS.ReadableStream): Promise<Buffer> {
static async streamToBuffer(src: Readable | NodeJS.ReadableStream | _Fetch.ReadableStream): Promise<Buffer> {
if ('getReader' in src) {
return this.streamToBuffer(this.fetchBodyToStream(src));
}
return new Promise<Buffer>((res, rej) => {

@@ -54,3 +81,3 @@ const data: Buffer[] = [];

return Buffer.from(src);
} else if (typeof src !== 'string' && 'pipe' in src) {
} else if (typeof src !== 'string' && ('pipe' in src || 'getReader' in src)) {
return this.streamToBuffer(src);

@@ -70,2 +97,4 @@ } else {

return src as Readable;
} else if (typeof src !== 'string' && 'getReader' in src) {
return this.fetchBodyToStream(src);
} else {

@@ -72,0 +101,0 @@ return this.bufferToStream(await this.toBuffer(src));

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc