From 597ee38ef28d040cbf4d629cf3d2bd3e89a70a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 28 Mar 2019 04:29:36 +0100 Subject: Rewrite readFile and writeFile (#2000) Using open/read/write --- js/files_test.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'js/files_test.ts') diff --git a/js/files_test.ts b/js/files_test.ts index 0decd9f00..f953946bc 100644 --- a/js/files_test.ts +++ b/js/files_test.ts @@ -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); -- cgit v1.2.3