-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
154 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@whatwg-node/node-fetch': minor | ||
'@whatwg-node/fetch': minor | ||
--- | ||
|
||
\`TextDecoderStream\` and \`TextEncoderStream\` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { PonyfillTextDecoder, PonyfillTextEncoder } from './TextEncoderDecoder.js'; | ||
import { PonyfillTransformStream } from './TransformStream.js'; | ||
|
||
export class PonyfillTextDecoderStream | ||
extends PonyfillTransformStream | ||
implements TextDecoderStream | ||
{ | ||
private textDecoder: TextDecoder; | ||
constructor(encoding?: BufferEncoding, options?: TextDecoderOptions) { | ||
super({ | ||
transform: (chunk, controller) => { | ||
controller.enqueue(this.textDecoder.decode(chunk, { stream: true })); | ||
}, | ||
}); | ||
this.textDecoder = new PonyfillTextDecoder(encoding, options); | ||
} | ||
|
||
get encoding(): string { | ||
return this.textDecoder.encoding; | ||
} | ||
|
||
get fatal(): boolean { | ||
return this.textDecoder.fatal; | ||
} | ||
|
||
get ignoreBOM(): boolean { | ||
return this.textDecoder.ignoreBOM; | ||
} | ||
} | ||
|
||
export class PonyfillTextEncoderStream | ||
extends PonyfillTransformStream | ||
implements TextEncoderStream | ||
{ | ||
private textEncoder: TextEncoder; | ||
constructor(encoding?: BufferEncoding) { | ||
super({ | ||
transform: (chunk, controller) => { | ||
controller.enqueue(this.textEncoder.encode(chunk)); | ||
}, | ||
}); | ||
this.textEncoder = new PonyfillTextEncoder(encoding); | ||
} | ||
|
||
get encoding(): string { | ||
return this.textEncoder.encoding; | ||
} | ||
|
||
encode(input: string): Uint8Array { | ||
return this.textEncoder.encode(input); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/node-fetch/tests/TextEncoderDecoderStream.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { PonyfillReadableStream } from '../src/ReadableStream'; | ||
import { PonyfillTextEncoder } from '../src/TextEncoderDecoder'; | ||
import { | ||
PonyfillTextDecoderStream, | ||
PonyfillTextEncoderStream, | ||
} from '../src/TextEncoderDecoderStream'; | ||
|
||
describe('TextEncoderDecoderStream', () => { | ||
it('TextEncoderStream', async () => { | ||
const readableStream = new PonyfillReadableStream({ | ||
start(controller) { | ||
controller.enqueue(Buffer.from('Hello, ')); | ||
controller.enqueue(Buffer.from('world!')); | ||
controller.close(); | ||
}, | ||
}); | ||
const pipedStream = readableStream.pipeThrough(new PonyfillTextEncoderStream()); | ||
const reader = pipedStream.getReader(); | ||
const chunks: Uint8Array[] = []; | ||
while (true) { | ||
const { done, value } = await reader.read(); | ||
if (done) { | ||
break; | ||
} | ||
chunks.push(value); | ||
} | ||
const encoded = Buffer.concat(chunks); | ||
expect(encoded.toString('utf-8')).toBe('Hello, world!'); | ||
}); | ||
it('TextDecoderStream', async () => { | ||
const textEncoder = new PonyfillTextEncoder(); | ||
const decodedHello = textEncoder.encode('Hello, '); | ||
const decodedWorld = textEncoder.encode('world!'); | ||
const readableStream = new PonyfillReadableStream({ | ||
start(controller) { | ||
controller.enqueue(decodedHello); | ||
controller.enqueue(decodedWorld); | ||
controller.close(); | ||
}, | ||
}); | ||
const chunks: string[] = []; | ||
const pipedStream = readableStream.pipeThrough(new PonyfillTextDecoderStream()); | ||
const reader = pipedStream.getReader(); | ||
while (true) { | ||
const { done, value } = await reader.read(); | ||
if (done) { | ||
break; | ||
} | ||
chunks.push(value); | ||
} | ||
expect(chunks.join('')).toBe('Hello, world!'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9499,7 +9499,6 @@ [email protected]: | |
|
||
uWebSockets.js@uNetworking/uWebSockets.js#v20.49.0: | ||
version "20.49.0" | ||
uid "442087c0a01bf146acb7386910739ec81df06700" | ||
resolved "https://codeload.github.com/uNetworking/uWebSockets.js/tar.gz/442087c0a01bf146acb7386910739ec81df06700" | ||
|
||
ufo@^1.5.4: | ||
|