Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions packages/client/lib/client/RESP2/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,38 @@ export default class RESP2Decoder {
this.currentStringComposer = this.stringComposer;
}

wantStream(want: boolean) {
this.#wantStream = want;
}

private writeStream(chunk: Buffer): void {
while (this.cursor < chunk.length) {
if (!this.type) {
this.currentStringComposer = this.streamComposer; /* TODO to be implemented */

this.type = chunk[this.cursor];
if (++this.cursor >= chunk.length) break;
}

if (!this.currentStream) {
this.currentStream = this.streamComposer.getStream();
this.options.onReply(this.currentStream);
}

const done = this.parseType(chunk, this.type);
if (done === undefined) break;

this.type = undefined;
this.currentStream = undefined;
}

this.cursor -= chunk.length;
}

write(chunk: Buffer): void {
if (this.#wantStream)
this.writeStream(chunk);

while (this.cursor < chunk.length) {
if (!this.type) {
this.currentStringComposer = this.options.returnStringsAsBuffers() ?
Expand Down
5 changes: 5 additions & 0 deletions packages/client/lib/client/commands-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,12 @@ export default class RedisCommandsQueue {
return encoded;
}

private currentCommandWantsStream() {
return false; /* TODO */
}

onReplyChunk(chunk: Buffer): void {
this.#decoder.wantStream( currentCommandWantsStream() );
this.#decoder.write(chunk);
}

Expand Down