Skip to content

Commit

Permalink
chore(types): fix accidental exposure of Buffer type to cloudflare (#709
Browse files Browse the repository at this point in the history
)
  • Loading branch information
stainless-bot committed Mar 6, 2024
1 parent 4753be2 commit 0323ecb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
13 changes: 12 additions & 1 deletion src/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class SSEDecoder {
*
* https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
*/
export class LineDecoder {
class LineDecoder {
// prettier-ignore
static NEWLINE_CHARS = new Set(['\n', '\r', '\x0b', '\x0c', '\x1c', '\x1d', '\x1e', '\x85', '\u2028', '\u2029']);
static NEWLINE_REGEXP = /\r\n|[\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029]/g;
Expand Down Expand Up @@ -372,6 +372,17 @@ export class LineDecoder {
}
}

/** This is an internal helper function that's just used for testing */
export function _decodeChunks(chunks: string[]): string[] {
const decoder = new LineDecoder();
const lines = [];
for (const chunk of chunks) {
lines.push(...decoder.decode(chunk));
}

return lines;
}

function partition(str: string, delimiter: string): [string, string, string] {
const index = str.indexOf(delimiter);
if (index !== -1) {
Expand Down
15 changes: 1 addition & 14 deletions tests/streaming.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
import { LineDecoder } from 'openai/streaming';

function decodeChunks(chunks: string[], decoder?: LineDecoder): string[] {
if (!decoder) {
decoder = new LineDecoder();
}

const lines = [];
for (const chunk of chunks) {
lines.push(...decoder.decode(chunk));
}

return lines;
}
import { _decodeChunks as decodeChunks } from 'openai/streaming';

describe('line decoder', () => {
test('basic', () => {
Expand Down

0 comments on commit 0323ecb

Please sign in to comment.