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 27dc6d5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 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);
});
2 changes: 1 addition & 1 deletion js/io.ts
Original file line number Diff line number Diff line change
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 27dc6d5

Please sign in to comment.