2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-07-17 09:10:34 -04:00
|
|
|
|
2024-09-05 03:22:52 -04:00
|
|
|
import { assert, assertEquals } from "@std/assert";
|
2024-07-25 01:30:28 -04:00
|
|
|
import { fromFileUrl, relative } from "@std/path";
|
2023-07-17 09:10:34 -04:00
|
|
|
import { pipeline } from "node:stream/promises";
|
2024-09-05 03:22:52 -04:00
|
|
|
// @ts-expect-error: @types/node is outdated
|
|
|
|
import { getDefaultHighWaterMark } from "node:stream";
|
2023-07-17 09:10:34 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
});
|
2024-09-05 03:22:52 -04:00
|
|
|
|
|
|
|
Deno.test("stream getDefaultHighWaterMark", () => {
|
|
|
|
assertEquals(getDefaultHighWaterMark(false), 16 * 1024);
|
|
|
|
assertEquals(getDefaultHighWaterMark(true), 16);
|
|
|
|
});
|