Skip to content

Commit

Permalink
Use Uint8Array instead of ArrayBufferView
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Nov 12, 2018
1 parent 92455a0 commit e931c53
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
10 changes: 2 additions & 8 deletions buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,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();
Expand All @@ -139,11 +136,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);
}

Expand Down
2 changes: 1 addition & 1 deletion bufio_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const testOutput = encoder.encode("0123456789abcdefghijklmnopqrstuvwxy");
class TestReader implements Reader {
constructor(private data: Uint8Array, private stride: number) {}

async read(buf: ArrayBufferView): Promise<ReadResult> {
async read(buf: Uint8Array): Promise<ReadResult> {
let nread = this.stride;
if (nread > this.data.byteLength) {
nread = this.data.byteLength;
Expand Down
3 changes: 2 additions & 1 deletion http_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const addr = "0.0.0.0:8000";
const s = serve(addr);
console.log(`listening on http://${addr}/`);

const body = new TextEncoder().encode("Hello World\n");
const body = (new TextEncoder()).encode("Hello World\n");


async function main() {
for await (const req of s) {
Expand Down
6 changes: 3 additions & 3 deletions iotest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Reader, ReadResult } from "deno";
export class OneByteReader implements Reader {
constructor(readonly r: Reader) {}

async read(p: ArrayBufferView): Promise<ReadResult> {
async read(p: Uint8Array): Promise<ReadResult> {
if (p.byteLength === 0) {
return { nread: 0, eof: false };
}
Expand All @@ -28,7 +28,7 @@ export class OneByteReader implements Reader {
export class HalfReader implements Reader {
constructor(readonly r: Reader) {}

async read(p: ArrayBufferView): Promise<ReadResult> {
async read(p: Uint8Array): Promise<ReadResult> {
if (!(p instanceof Uint8Array)) {
throw Error("expected Uint8Array");
}
Expand All @@ -51,7 +51,7 @@ export class TimeoutReader implements Reader {
count = 0;
constructor(readonly r: Reader) {}

async read(p: ArrayBufferView): Promise<ReadResult> {
async read(p: Uint8Array): Promise<ReadResult> {
this.count++;
if (this.count === 2) {
throw new ErrTimeout();
Expand Down

0 comments on commit e931c53

Please sign in to comment.