summaryrefslogtreecommitdiff
path: root/js/files_test.ts
blob: 37f63d9fa270adf2a78e1cb31f31b2e50618879d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import * as deno from "deno";
import { test, assert, assertEqual } from "./test_util.ts";

test(function filesStdioFileDescriptors() {
  assertEqual(deno.stdin.rid, 0);
  assertEqual(deno.stdout.rid, 1);
  assertEqual(deno.stderr.rid, 2);
});

test(async function filesCopyToStdout() {
  const filename = "package.json";
  const file = await deno.open(filename);
  assert(file.rid > 2);
  const bytesWritten = await deno.copy(deno.stdout, file);
  const fileSize = deno.statSync(filename).len;
  assertEqual(bytesWritten, fileSize);
  console.log("bytes written", bytesWritten);
});

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

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

  assertEqual(totalSize, 12);
});