mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
fix(runtime): support reading /proc using readFile (#12839)
This commit is contained in:
parent
429c773a2e
commit
3cc724c9ba
3 changed files with 37 additions and 12 deletions
|
@ -105,15 +105,10 @@ unitTest(
|
|||
);
|
||||
|
||||
unitTest(
|
||||
{ permissions: { read: true } },
|
||||
async function readTextileWithAbortSignal() {
|
||||
const ac = new AbortController();
|
||||
queueMicrotask(() => ac.abort());
|
||||
await assertRejects(async () => {
|
||||
await Deno.readTextFile("cli/tests/testdata/fixture.json", {
|
||||
signal: ac.signal,
|
||||
});
|
||||
});
|
||||
{ permissions: { read: true }, ignore: Deno.build.os !== "linux" },
|
||||
async function readFileProcFs() {
|
||||
const data = await Deno.readFile("/proc/self/stat");
|
||||
assert(data.byteLength > 0);
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -83,3 +83,24 @@ unitTest(
|
|||
assertEquals(resourcesBefore, Deno.resources());
|
||||
},
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ permissions: { read: true } },
|
||||
async function readTextFileWithAbortSignal() {
|
||||
const ac = new AbortController();
|
||||
queueMicrotask(() => ac.abort());
|
||||
await assertRejects(async () => {
|
||||
await Deno.readFile("cli/tests/testdata/fixture.json", {
|
||||
signal: ac.signal,
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ permissions: { read: true }, ignore: Deno.build.os !== "linux" },
|
||||
async function readTextFileProcFs() {
|
||||
const data = await Deno.readTextFile("/proc/self/stat");
|
||||
assert(data.length > 0);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -4,13 +4,18 @@
|
|||
((window) => {
|
||||
const core = window.Deno.core;
|
||||
const { open, openSync } = window.__bootstrap.files;
|
||||
const { readAllSyncSized, readAllInnerSized } = window.__bootstrap.io;
|
||||
const { readAllSync, readAll, readAllSyncSized, readAllInnerSized } =
|
||||
window.__bootstrap.io;
|
||||
|
||||
function readFileSync(path) {
|
||||
const file = openSync(path);
|
||||
try {
|
||||
const { size } = file.statSync();
|
||||
return readAllSyncSized(file, size);
|
||||
if (size === 0) {
|
||||
return readAllSync(file);
|
||||
} else {
|
||||
return readAllSyncSized(file, size);
|
||||
}
|
||||
} finally {
|
||||
file.close();
|
||||
}
|
||||
|
@ -20,7 +25,11 @@
|
|||
const file = await open(path);
|
||||
try {
|
||||
const { size } = await file.stat();
|
||||
return await readAllInnerSized(file, size, options);
|
||||
if (size === 0) {
|
||||
return await readAll(file);
|
||||
} else {
|
||||
return await readAllInnerSized(file, size, options);
|
||||
}
|
||||
} finally {
|
||||
file.close();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue