-
Notifications
You must be signed in to change notification settings - Fork 163
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
3 changed files
with
50 additions
and
13 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
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,24 @@ | ||
class BaseStreamWriter<T> { | ||
protected writableStream: WritableStream<T>; | ||
|
||
protected defaultWriter: WritableStreamDefaultWriter<T>; | ||
|
||
constructor(writableStream: WritableStream<T>) { | ||
this.writableStream = writableStream; | ||
this.defaultWriter = writableStream.getWriter(); | ||
} | ||
|
||
write(chunk: T): Promise<void> { | ||
return this.defaultWriter.write(chunk); | ||
} | ||
|
||
async close() { | ||
await this.defaultWriter.close(); | ||
this.defaultWriter.releaseLock(); | ||
console.log('stream status', this.writableStream.locked); | ||
} | ||
} | ||
|
||
export class TextStreamWriter extends BaseStreamWriter<string> {} | ||
|
||
export class BinaryStreamWriter extends BaseStreamWriter<Uint8Array> {} |
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