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(
|
unitTest(
|
||||||
{ permissions: { read: true } },
|
{ permissions: { read: true }, ignore: Deno.build.os !== "linux" },
|
||||||
async function readTextileWithAbortSignal() {
|
async function readFileProcFs() {
|
||||||
const ac = new AbortController();
|
const data = await Deno.readFile("/proc/self/stat");
|
||||||
queueMicrotask(() => ac.abort());
|
assert(data.byteLength > 0);
|
||||||
await assertRejects(async () => {
|
|
||||||
await Deno.readTextFile("cli/tests/testdata/fixture.json", {
|
|
||||||
signal: ac.signal,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -83,3 +83,24 @@ unitTest(
|
||||||
assertEquals(resourcesBefore, Deno.resources());
|
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) => {
|
((window) => {
|
||||||
const core = window.Deno.core;
|
const core = window.Deno.core;
|
||||||
const { open, openSync } = window.__bootstrap.files;
|
const { open, openSync } = window.__bootstrap.files;
|
||||||
const { readAllSyncSized, readAllInnerSized } = window.__bootstrap.io;
|
const { readAllSync, readAll, readAllSyncSized, readAllInnerSized } =
|
||||||
|
window.__bootstrap.io;
|
||||||
|
|
||||||
function readFileSync(path) {
|
function readFileSync(path) {
|
||||||
const file = openSync(path);
|
const file = openSync(path);
|
||||||
try {
|
try {
|
||||||
const { size } = file.statSync();
|
const { size } = file.statSync();
|
||||||
return readAllSyncSized(file, size);
|
if (size === 0) {
|
||||||
|
return readAllSync(file);
|
||||||
|
} else {
|
||||||
|
return readAllSyncSized(file, size);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
@ -20,7 +25,11 @@
|
||||||
const file = await open(path);
|
const file = await open(path);
|
||||||
try {
|
try {
|
||||||
const { size } = await file.stat();
|
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 {
|
} finally {
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue