mirror of
https://github.com/denoland/deno.git
synced 2025-08-15 16:20:26 +00:00
parent
d0b6152f11
commit
597ee38ef2
10 changed files with 337 additions and 190 deletions
|
@ -163,6 +163,19 @@ testPerm({ read: true }, async function seekStart() {
|
|||
assertEquals(decoded, "world!");
|
||||
});
|
||||
|
||||
testPerm({ read: true }, function seekSyncStart() {
|
||||
const filename = "tests/hello.txt";
|
||||
const file = Deno.openSync(filename);
|
||||
// Deliberately move 1 step forward
|
||||
file.readSync(new Uint8Array(1)); // "H"
|
||||
// Skipping "Hello "
|
||||
file.seekSync(6, Deno.SeekMode.SEEK_START);
|
||||
const buf = new Uint8Array(6);
|
||||
file.readSync(buf);
|
||||
const decoded = new TextDecoder().decode(buf);
|
||||
assertEquals(decoded, "world!");
|
||||
});
|
||||
|
||||
testPerm({ read: true }, async function seekCurrent() {
|
||||
const filename = "tests/hello.txt";
|
||||
const file = await Deno.open(filename);
|
||||
|
@ -176,6 +189,19 @@ testPerm({ read: true }, async function seekCurrent() {
|
|||
assertEquals(decoded, "world!");
|
||||
});
|
||||
|
||||
testPerm({ read: true }, function seekSyncCurrent() {
|
||||
const filename = "tests/hello.txt";
|
||||
const file = Deno.openSync(filename);
|
||||
// Deliberately move 1 step forward
|
||||
file.readSync(new Uint8Array(1)); // "H"
|
||||
// Skipping "ello "
|
||||
file.seekSync(5, Deno.SeekMode.SEEK_CURRENT);
|
||||
const buf = new Uint8Array(6);
|
||||
file.readSync(buf);
|
||||
const decoded = new TextDecoder().decode(buf);
|
||||
assertEquals(decoded, "world!");
|
||||
});
|
||||
|
||||
testPerm({ read: true }, async function seekEnd() {
|
||||
const filename = "tests/hello.txt";
|
||||
const file = await Deno.open(filename);
|
||||
|
@ -186,6 +212,16 @@ testPerm({ read: true }, async function seekEnd() {
|
|||
assertEquals(decoded, "world!");
|
||||
});
|
||||
|
||||
testPerm({ read: true }, function seekSyncEnd() {
|
||||
const filename = "tests/hello.txt";
|
||||
const file = Deno.openSync(filename);
|
||||
file.seekSync(-6, Deno.SeekMode.SEEK_END);
|
||||
const buf = new Uint8Array(6);
|
||||
file.readSync(buf);
|
||||
const decoded = new TextDecoder().decode(buf);
|
||||
assertEquals(decoded, "world!");
|
||||
});
|
||||
|
||||
testPerm({ read: true }, async function seekMode() {
|
||||
const filename = "tests/hello.txt";
|
||||
const file = await Deno.open(filename);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue