Skip to content

Commit

Permalink
rename toAsyncIterator, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju committed Oct 31, 2018
1 parent 7c8483d commit cf6e663
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion js/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export { chdir, cwd } from "./dir";
export { File, open, stdin, stdout, stderr, read, write, close } from "./files";
export {
copy,
readerIterator,
toAsyncIterator,
ReadResult,
Reader,
Writer,
Expand Down
13 changes: 13 additions & 0 deletions js/files_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@ test(async function filesCopyToStdout() {
assertEqual(bytesWritten, fileSize);
console.log("bytes written", bytesWritten);
});

test(async function filesToAsyncIterator() {
const filename = 'tests/hello.txt';
const file = await deno.open(filename);
const fileSize = deno.statSync(filename).len;

let totalSize = 0;
for await (const buf of deno.toAsyncIterator(file)) {
totalSize += buf.byteLength;
}

assertEqual(totalSize, fileSize);
});
4 changes: 2 additions & 2 deletions js/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface Reader {
* of bytes read (`0` <= `n` <= `p.byteLength`) and any error encountered.
* Even if `read()` returns `n` < `p.byteLength`, it may use all of `p` as
* scratch space during the call. If some data is available but not
* `p.byteLength` , `read()` conventionally returns what is available
* `p.byteLength` bytes, `read()` conventionally returns what is available
* instead of waiting for more.
*
* When `read()` encounters an error or end-of-file condition after
Expand Down Expand Up @@ -123,7 +123,7 @@ export async function copy(dst: Writer, src: Reader): Promise<number> {
* console.log(chunk)
* }
*/
export function readerIterator(
export function toAsyncIterator(
r: Reader
): AsyncIterableIterator<ArrayBufferView> {
const b = new Uint8Array(1024);
Expand Down

0 comments on commit cf6e663

Please sign in to comment.