summaryrefslogtreecommitdiff
path: root/js/io.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-11-08 01:18:21 -0500
committerRyan Dahl <ry@tinyclouds.org>2018-11-09 07:22:05 -0800
commit1f2c92c7c88ce6619624520ec7e6b9a1f57d445b (patch)
tree4948ad4fb6491b67310d02f0fab42eb82c11dca0 /js/io.ts
parent98e6366cb5f00b99340466a9adb3aa82850785fa (diff)
Reader/Writer should use Uint8Array not ArrayBufferView
Because many Reader/Writer implementations (e.g. bufio) assume their able to use subarray() with byte indexes and often ask for byte values, it makes sense to simply restrict all implementations to Uint8Array.
Diffstat (limited to 'js/io.ts')
-rw-r--r--js/io.ts10
1 files changed, 4 insertions, 6 deletions
diff --git a/js/io.ts b/js/io.ts
index 4e37355bb..74b30cd94 100644
--- a/js/io.ts
+++ b/js/io.ts
@@ -37,7 +37,7 @@ export interface Reader {
*
* Implementations must not retain `p`.
*/
- read(p: ArrayBufferView): Promise<ReadResult>;
+ read(p: Uint8Array): Promise<ReadResult>;
}
// Writer is the interface that wraps the basic write() method.
@@ -51,7 +51,7 @@ export interface Writer {
*
* Implementations must not retain `p`.
*/
- write(p: ArrayBufferView): Promise<number>;
+ write(p: Uint8Array): Promise<number>;
}
// https://golang.org/pkg/io/#Closer
@@ -123,9 +123,7 @@ export async function copy(dst: Writer, src: Reader): Promise<number> {
* console.log(chunk)
* }
*/
-export function toAsyncIterator(
- r: Reader
-): AsyncIterableIterator<ArrayBufferView> {
+export function toAsyncIterator(r: Reader): AsyncIterableIterator<Uint8Array> {
const b = new Uint8Array(1024);
return {
@@ -133,7 +131,7 @@ export function toAsyncIterator(
return this;
},
- async next(): Promise<IteratorResult<ArrayBufferView>> {
+ async next(): Promise<IteratorResult<Uint8Array>> {
const result = await r.read(b);
return {
value: b.subarray(0, result.nread),