Skip to content

Commit e0deb22

Browse files
committed
chore(types): fix accidental exposure of Buffer type to cloudflare (#709)
1 parent 753bced commit e0deb22

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/streaming.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class SSEDecoder {
267267
*
268268
* https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
269269
*/
270-
export class LineDecoder {
270+
class LineDecoder {
271271
// prettier-ignore
272272
static NEWLINE_CHARS = new Set(['\n', '\r', '\x0b', '\x0c', '\x1c', '\x1d', '\x1e', '\x85', '\u2028', '\u2029']);
273273
static NEWLINE_REGEXP = /\r\n|[\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029]/g;
@@ -372,6 +372,17 @@ export class LineDecoder {
372372
}
373373
}
374374

375+
/** This is an internal helper function that's just used for testing */
376+
export function _decodeChunks(chunks: string[]): string[] {
377+
const decoder = new LineDecoder();
378+
const lines = [];
379+
for (const chunk of chunks) {
380+
lines.push(...decoder.decode(chunk));
381+
}
382+
383+
return lines;
384+
}
385+
375386
function partition(str: string, delimiter: string): [string, string, string] {
376387
const index = str.indexOf(delimiter);
377388
if (index !== -1) {

tests/streaming.test.ts

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
1-
import { LineDecoder } from 'openai/streaming';
2-
3-
function decodeChunks(chunks: string[], decoder?: LineDecoder): string[] {
4-
if (!decoder) {
5-
decoder = new LineDecoder();
6-
}
7-
8-
const lines = [];
9-
for (const chunk of chunks) {
10-
lines.push(...decoder.decode(chunk));
11-
}
12-
13-
return lines;
14-
}
1+
import { _decodeChunks as decodeChunks } from 'openai/streaming';
152

163
describe('line decoder', () => {
174
test('basic', () => {

0 commit comments

Comments
 (0)