File tree Expand file tree Collapse file tree 5 files changed +21
-10
lines changed Expand file tree Collapse file tree 5 files changed +21
-10
lines changed Original file line number Diff line number Diff line change 2
2
" @smithy/util-stream " : minor
3
3
---
4
4
5
- add stream splitting to sdkStreamMixin
5
+ add splitStream and headStream utilities
Original file line number Diff line number Diff line change 1
1
import { Readable , Writable } from "stream" ;
2
2
3
3
import { headStream as headWebStream } from "./headStream.browser" ;
4
+ import { isReadableStreamInstance } from "./isReadableStream" ;
4
5
5
6
/**
6
7
* @internal
@@ -11,7 +12,6 @@ import { headStream as headWebStream } from "./headStream.browser";
11
12
*/
12
13
export const headStream = ( stream : Readable | ReadableStream , bytes : number ) : Promise < Uint8Array > => {
13
14
if ( isReadableStreamInstance ( stream ) ) {
14
- // Web stream API in Node.js
15
15
return headWebStream ( stream , bytes ) ;
16
16
}
17
17
return new Promise ( ( resolve , reject ) => {
@@ -47,6 +47,3 @@ class Collector extends Writable {
47
47
callback ( ) ;
48
48
}
49
49
}
50
-
51
- const isReadableStreamInstance = ( stream : unknown ) : stream is ReadableStream =>
52
- typeof ReadableStream === "function" && stream instanceof ReadableStream ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @internal
3
+ */
4
+ export const isReadableStreamInstance = ( stream : unknown ) : stream is ReadableStream =>
5
+ typeof ReadableStream === "function" && stream ?. constructor ?. name === ReadableStream . name ;
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import { toBase64 } from "@smithy/util-base64";
4
4
import { toHex } from "@smithy/util-hex-encoding" ;
5
5
import { toUtf8 } from "@smithy/util-utf8" ;
6
6
7
+ import { isReadableStreamInstance } from "./isReadableStream" ;
8
+
7
9
const ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED = "The stream has already been transformed." ;
8
10
9
11
/**
@@ -74,6 +76,3 @@ export const sdkStreamMixin = (stream: unknown): SdkStream<ReadableStream | Blob
74
76
} ;
75
77
76
78
const isBlobInstance = ( stream : unknown ) : stream is Blob => typeof Blob === "function" && stream instanceof Blob ;
77
-
78
- const isReadableStreamInstance = ( stream : unknown ) : stream is ReadableStream =>
79
- typeof ReadableStream === "function" && stream instanceof ReadableStream ;
Original file line number Diff line number Diff line change 1
- import type { Readable as IReadable } from "stream" ;
1
+ import type { Readable } from "stream" ;
2
2
import { PassThrough } from "stream" ;
3
3
4
+ import { isReadableStreamInstance } from "./isReadableStream" ;
5
+ import { splitStream as splitWebStream } from "./splitStream.browser" ;
6
+
4
7
/**
5
8
* @param stream
6
9
* @returns stream split into two identical streams.
7
10
*/
8
- export async function splitStream ( stream : IReadable ) : Promise < [ IReadable , IReadable ] > {
11
+ export async function splitStream ( stream : Readable ) : Promise < [ Readable , Readable ] > ;
12
+ export async function splitStream ( stream : ReadableStream ) : Promise < [ ReadableStream , ReadableStream ] > ;
13
+ export async function splitStream (
14
+ stream : Readable | ReadableStream
15
+ ) : Promise < [ Readable | ReadableStream , Readable | ReadableStream ] > {
16
+ if ( isReadableStreamInstance ( stream ) ) {
17
+ return splitWebStream ( stream ) ;
18
+ }
9
19
const stream1 = new PassThrough ( ) ;
10
20
const stream2 = new PassThrough ( ) ;
11
21
stream . pipe ( stream1 ) ;
You can’t perform that action at this time.
0 commit comments