2024-01-01 19:58:21 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-07-17 13:10:34 +00:00
|
|
|
|
2024-02-13 02:05:10 +00:00
|
|
|
import { assert } from "@std/assert/mod.ts";
|
|
|
|
import { fromFileUrl, relative } from "@std/path/mod.ts";
|
2023-07-17 13:10:34 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
});
|