1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00
denoland-deno/tests/unit_node/stream_test.ts

26 lines
802 B
TypeScript
Raw Normal View History

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assert } from "@std/assert";
import { fromFileUrl, relative } from "@std/path";
import { pipeline } from "node:stream/promises";
import { createReadStream, createWriteStream } from "node:fs";
Deno.test("stream/promises pipeline", async () => {
const filePath = relative(
Deno.cwd(),
fromFileUrl(new URL("./testdata/lorem_ipsum.txt", import.meta.url)),
);
const input = createReadStream(filePath);
const output = createWriteStream("lorem_ipsum.txt.copy");
await pipeline(input, output);
const content = Deno.readTextFileSync("lorem_ipsum.txt.copy");
assert(content.startsWith("Lorem ipsum dolor sit amet"));
try {
Deno.removeSync("lorem_ipsum.txt.copy");
} catch {
// pass
}
});