1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00

fix(runtime): support reading /proc using readFile (#12839)

This commit is contained in:
Luca Casonato 2021-11-22 16:53:58 +01:00 committed by GitHub
parent 429c773a2e
commit 3cc724c9ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 12 deletions

View file

@ -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);
},
);

View file

@ -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);
},
);

View file

@ -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();
}