Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(io/buffer): make Buffer compatible with Deploy #912

Merged
merged 3 commits into from
May 14, 2021
Merged
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions io/buffer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { assert } from "../_util/assert.ts";
import { copy } from "../bytes/mod.ts";

interface Reader {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to have a io/types.d.ts and put the Reader*/Writer*, etc and then import type from there? It would solve part of denoland/deno#9795. I wouldn't necessarily refactor all of io to use them at the moment, but it would be better than just burying them in buffer.ts while all of io and other std modules should move over to these.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would make more sense and sounds natural. Updated.

read(p: Uint8Array): Promise<number | null>;
}

interface ReaderSync {
readSync(p: Uint8Array): number | null;
}

// MIN_READ is the minimum ArrayBuffer size passed to a read call by
// buffer.ReadFrom. As long as the Buffer has at least MIN_READ bytes beyond
// what is required to hold the contents of r, readFrom() will not grow the
Expand Down Expand Up @@ -189,7 +197,7 @@ export class Buffer {
*
* Based on Go Lang's
* [Buffer.ReadFrom](https://golang.org/pkg/bytes/#Buffer.ReadFrom). */
async readFrom(r: Deno.Reader): Promise<number> {
async readFrom(r: Reader): Promise<number> {
let n = 0;
const tmp = new Uint8Array(MIN_READ);
while (true) {
Expand Down Expand Up @@ -219,7 +227,7 @@ export class Buffer {
*
* Based on Go Lang's
* [Buffer.ReadFrom](https://golang.org/pkg/bytes/#Buffer.ReadFrom). */
readFromSync(r: Deno.ReaderSync): number {
readFromSync(r: ReaderSync): number {
let n = 0;
const tmp = new Uint8Array(MIN_READ);
while (true) {
Expand Down