mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +00:00
test(firmware): share the short positional read fixture (#16953)
This commit is contained in:
1 parent
47443f4c64
commit
2ddfb362ff
3 files changed
+35
-56
No files matched your search
+31
@@ -0,0 +1,31 @@
|
||||
import { lstat, open, realpath } from "node:fs/promises";
|
||||
import type { StableArtifactFileSystem } from "../../src/resources/readStableArtifact.js";
|
||||
|
||||
export const shortReadAfterStreamFileSystem = (): StableArtifactFileSystem => ({
|
||||
lstat: (path) => lstat(path, { bigint: true }),
|
||||
realpath,
|
||||
open: async (path, flags, mode) => {
|
||||
const handle = await open(path, flags, mode);
|
||||
const originalRead = handle.read.bind(handle);
|
||||
let streamed = false;
|
||||
handle.read = (async (
|
||||
buffer: Buffer,
|
||||
bufOffset?: number | null,
|
||||
length?: number | null,
|
||||
position?: number | bigint | null,
|
||||
) => {
|
||||
const res = await originalRead(
|
||||
buffer,
|
||||
bufOffset ?? 0,
|
||||
length ?? buffer.length,
|
||||
position ?? null,
|
||||
);
|
||||
if (res.bytesRead === 0) streamed = true;
|
||||
else if (streamed && typeof position === "number" && position > 0) {
|
||||
return { bytesRead: 0, buffer };
|
||||
}
|
||||
return res;
|
||||
}) as typeof handle.read;
|
||||
return handle;
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user