diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2023-01-19 05:30:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-19 05:30:56 +0100 |
commit | 18e8ce4ca5daaefcde243ff54b995f3cd3e16c7b (patch) | |
tree | 107fe4b619cc0326dc4f3c39669d2559851f8452 | |
parent | 84e9794970e998aaa510a526160258905a092d05 (diff) |
feat(runtime): add bigint to seek typings (#17314)
-rw-r--r-- | cli/tests/unit/files_test.ts | 17 | ||||
-rw-r--r-- | cli/tsc/dts/lib.deno.ns.d.ts | 8 |
2 files changed, 21 insertions, 4 deletions
diff --git a/cli/tests/unit/files_test.ts b/cli/tests/unit/files_test.ts index c30ef2a71..2ea202536 100644 --- a/cli/tests/unit/files_test.ts +++ b/cli/tests/unit/files_test.ts @@ -574,6 +574,23 @@ Deno.test({ permissions: { read: true } }, async function seekStart() { file.close(); }); +Deno.test({ permissions: { read: true } }, async function seekStartBigInt() { + const filename = "cli/tests/testdata/assets/hello.txt"; + const file = await Deno.open(filename); + const seekPosition = 6n; + // Deliberately move 1 step forward + await file.read(new Uint8Array(1)); // "H" + // Skipping "Hello " + // seeking from beginning of a file plus seekPosition + const cursorPosition = await file.seek(seekPosition, Deno.SeekMode.Start); + assertEquals(seekPosition, BigInt(cursorPosition)); + const buf = new Uint8Array(6); + await file.read(buf); + const decoded = new TextDecoder().decode(buf); + assertEquals(decoded, "world!"); + file.close(); +}); + Deno.test({ permissions: { read: true } }, function seekSyncStart() { const filename = "cli/tests/testdata/assets/hello.txt"; const file = Deno.openSync(filename); diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index b3f2adc99..7473b1415 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -1498,7 +1498,7 @@ declare namespace Deno { * * It resolves with the updated offset. */ - seek(offset: number, whence: SeekMode): Promise<number>; + seek(offset: number | bigint, whence: SeekMode): Promise<number>; } /** @@ -1799,7 +1799,7 @@ declare namespace Deno { */ export function seek( rid: number, - offset: number, + offset: number | bigint, whence: SeekMode, ): Promise<number>; @@ -2163,7 +2163,7 @@ declare namespace Deno { * console.log(await file.seek(-2, Deno.SeekMode.End)); // "9" (e.g. 11-2) * ``` */ - seek(offset: number, whence: SeekMode): Promise<number>; + seek(offset: number | bigint, whence: SeekMode): Promise<number>; /** Synchronously seek to the given `offset` under mode given by `whence`. * The new position within the resource (bytes from the start) is returned. * @@ -2202,7 +2202,7 @@ declare namespace Deno { * file.close(); * ``` */ - seekSync(offset: number, whence: SeekMode): number; + seekSync(offset: number | bigint, whence: SeekMode): number; /** Resolves to a {@linkcode Deno.FileInfo} for the file. * * ```ts |