summaryrefslogtreecommitdiff
path: root/js/buffer.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/buffer.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/buffer.ts')
-rw-r--r--js/buffer.ts10
1 files changed, 2 insertions, 8 deletions
diff --git a/js/buffer.ts b/js/buffer.ts
index ca92698d0..f53f6b25d 100644
--- a/js/buffer.ts
+++ b/js/buffer.ts
@@ -127,10 +127,7 @@ export class Buffer implements Reader, Writer {
* is drained. The return value n is the number of bytes read. If the
* buffer has no data to return, eof in the response will be true.
*/
- async read(p: ArrayBufferView): Promise<ReadResult> {
- if (!(p instanceof Uint8Array)) {
- throw Error("Only Uint8Array supported");
- }
+ async read(p: Uint8Array): Promise<ReadResult> {
if (this.empty()) {
// Buffer is empty, reset to recover space.
this.reset();
@@ -146,11 +143,8 @@ export class Buffer implements Reader, Writer {
return { nread, eof: false };
}
- async write(p: ArrayBufferView): Promise<number> {
+ async write(p: Uint8Array): Promise<number> {
const m = this._grow(p.byteLength);
- if (!(p instanceof Uint8Array)) {
- throw Error("Only Uint8Array supported");
- }
return copyBytes(this.buf, p, m);
}