1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

feat(runtime): add bigint to seek typings (#17314)

This commit is contained in:
Leo Kettmeir 2023-01-19 05:30:56 +01:00 committed by GitHub
parent 84e9794970
commit 18e8ce4ca5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View file

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

View file

@ -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