mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
refactor: rename SeekMode variants to camelCase and stabilize (#4946)
This commit is contained in:
parent
30dc9bb748
commit
dea3ca39ba
3 changed files with 27 additions and 40 deletions
|
@ -11,9 +11,9 @@ const DEFAULT_BUFFER_SIZE = 32 * 1024;
|
|||
// Seek whence values.
|
||||
// https://golang.org/pkg/io/#pkg-constants
|
||||
export enum SeekMode {
|
||||
SEEK_START = 0,
|
||||
SEEK_CURRENT = 1,
|
||||
SEEK_END = 2,
|
||||
Start = 0,
|
||||
Current = 1,
|
||||
End = 2,
|
||||
}
|
||||
|
||||
// Reader is the interface that wraps the basic read() method.
|
||||
|
|
35
cli/js/lib.deno.ns.d.ts
vendored
35
cli/js/lib.deno.ns.d.ts
vendored
|
@ -383,11 +383,10 @@ declare namespace Deno {
|
|||
export const EOF: unique symbol;
|
||||
export type EOF = typeof EOF;
|
||||
|
||||
/** **UNSTABLE**: might remove `"SEEK_"` prefix. Might not use all-caps. */
|
||||
export enum SeekMode {
|
||||
SEEK_START = 0,
|
||||
SEEK_CURRENT = 1,
|
||||
SEEK_END = 2,
|
||||
Start = 0,
|
||||
Current = 1,
|
||||
End = 2,
|
||||
}
|
||||
|
||||
export interface Reader {
|
||||
|
@ -470,9 +469,9 @@ declare namespace Deno {
|
|||
|
||||
export interface Seeker {
|
||||
/** Seek sets the offset for the next `read()` or `write()` to offset,
|
||||
* interpreted according to `whence`: `SEEK_START` means relative to the
|
||||
* start of the file, `SEEK_CURRENT` means relative to the current offset,
|
||||
* and `SEEK_END` means relative to the end. Seek resolves to the new offset
|
||||
* interpreted according to `whence`: `Start` means relative to the
|
||||
* start of the file, `Current` means relative to the current offset,
|
||||
* and `End` means relative to the end. Seek resolves to the new offset
|
||||
* relative to the start of the file.
|
||||
*
|
||||
* Seeking to an offset before the start of the file is an error. Seeking to
|
||||
|
@ -485,9 +484,9 @@ declare namespace Deno {
|
|||
|
||||
export interface SyncSeeker {
|
||||
/** Seek sets the offset for the next `readSync()` or `writeSync()` to
|
||||
* offset, interpreted according to `whence`: `SEEK_START` means relative
|
||||
* to the start of the file, `SEEK_CURRENT` means relative to the current
|
||||
* offset, and `SEEK_END` means relative to the end.
|
||||
* offset, interpreted according to `whence`: `Start` means relative
|
||||
* to the start of the file, `Current` means relative to the current
|
||||
* offset, and `End` means relative to the end.
|
||||
*
|
||||
* Seeking to an offset before the start of the file is an error. Seeking to
|
||||
* any positive offset is legal, but the behavior of subsequent I/O
|
||||
|
@ -695,7 +694,7 @@ declare namespace Deno {
|
|||
* const file = Deno.openSync('hello.txt', {read: true, write: true, truncate: true, create: true});
|
||||
* Deno.writeSync(file.rid, new TextEncoder().encode("Hello world"));
|
||||
* // advance cursor 6 bytes
|
||||
* const cursorPosition = Deno.seekSync(file.rid, 6, Deno.SeekMode.SEEK_START);
|
||||
* const cursorPosition = Deno.seekSync(file.rid, 6, Deno.SeekMode.Start);
|
||||
* console.log(cursorPosition); // 6
|
||||
* const buf = new Uint8Array(100);
|
||||
* file.readSync(buf);
|
||||
|
@ -705,11 +704,11 @@ declare namespace Deno {
|
|||
*
|
||||
* // Given file.rid pointing to file with "Hello world", which is 11 bytes long:
|
||||
* // Seek 6 bytes from the start of the file
|
||||
* console.log(Deno.seekSync(file.rid, 6, Deno.SeekMode.SEEK_START)); // "6"
|
||||
* console.log(Deno.seekSync(file.rid, 6, Deno.SeekMode.Start)); // "6"
|
||||
* // Seek 2 more bytes from the current position
|
||||
* console.log(Deno.seekSync(file.rid, 2, Deno.SeekMode.SEEK_CURRENT)); // "8"
|
||||
* console.log(Deno.seekSync(file.rid, 2, Deno.SeekMode.Current)); // "8"
|
||||
* // Seek backwards 2 bytes from the end of the file
|
||||
* console.log(Deno.seekSync(file.rid, -2, Deno.SeekMode.SEEK_END)); // "9" (e.g. 11-2)
|
||||
* console.log(Deno.seekSync(file.rid, -2, Deno.SeekMode.End)); // "9" (e.g. 11-2)
|
||||
*/
|
||||
export function seekSync(
|
||||
rid: number,
|
||||
|
@ -723,7 +722,7 @@ declare namespace Deno {
|
|||
* const file = await Deno.open('hello.txt', {read: true, write: true, truncate: true, create: true});
|
||||
* await Deno.write(file.rid, new TextEncoder().encode("Hello world"));
|
||||
* // advance cursor 6 bytes
|
||||
* const cursorPosition = await Deno.seek(file.rid, 6, Deno.SeekMode.SEEK_START);
|
||||
* const cursorPosition = await Deno.seek(file.rid, 6, Deno.SeekMode.Start);
|
||||
* console.log(cursorPosition); // 6
|
||||
* const buf = new Uint8Array(100);
|
||||
* await file.read(buf);
|
||||
|
@ -733,11 +732,11 @@ declare namespace Deno {
|
|||
*
|
||||
* // Given file.rid pointing to file with "Hello world", which is 11 bytes long:
|
||||
* // Seek 6 bytes from the start of the file
|
||||
* console.log(await Deno.seek(file.rid, 6, Deno.SeekMode.SEEK_START)); // "6"
|
||||
* console.log(await Deno.seek(file.rid, 6, Deno.SeekMode.Start)); // "6"
|
||||
* // Seek 2 more bytes from the current position
|
||||
* console.log(await Deno.seek(file.rid, 2, Deno.SeekMode.SEEK_CURRENT)); // "8"
|
||||
* console.log(await Deno.seek(file.rid, 2, Deno.SeekMode.Current)); // "8"
|
||||
* // Seek backwards 2 bytes from the end of the file
|
||||
* console.log(await Deno.seek(file.rid, -2, Deno.SeekMode.SEEK_END)); // "9" (e.g. 11-2)
|
||||
* console.log(await Deno.seek(file.rid, -2, Deno.SeekMode.End)); // "9" (e.g. 11-2)
|
||||
*/
|
||||
export function seek(
|
||||
rid: number,
|
||||
|
|
|
@ -441,10 +441,7 @@ unitTest(
|
|||
|
||||
const buf = new Uint8Array(20);
|
||||
// seeking from beginning of a file
|
||||
const cursorPosition = await file.seek(
|
||||
seekPosition,
|
||||
Deno.SeekMode.SEEK_START
|
||||
);
|
||||
const cursorPosition = await file.seek(seekPosition, Deno.SeekMode.Start);
|
||||
assertEquals(seekPosition, cursorPosition);
|
||||
const result = await file.read(buf);
|
||||
assertEquals(result, 13);
|
||||
|
@ -462,10 +459,7 @@ unitTest({ perms: { read: true } }, async function seekStart(): Promise<void> {
|
|||
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.SEEK_START
|
||||
);
|
||||
const cursorPosition = await file.seek(seekPosition, Deno.SeekMode.Start);
|
||||
assertEquals(seekPosition, cursorPosition);
|
||||
const buf = new Uint8Array(6);
|
||||
await file.read(buf);
|
||||
|
@ -482,7 +476,7 @@ unitTest({ perms: { read: true } }, function seekSyncStart(): void {
|
|||
file.readSync(new Uint8Array(1)); // "H"
|
||||
// Skipping "Hello "
|
||||
// seeking from beginning of a file plus seekPosition
|
||||
const cursorPosition = file.seekSync(seekPosition, Deno.SeekMode.SEEK_START);
|
||||
const cursorPosition = file.seekSync(seekPosition, Deno.SeekMode.Start);
|
||||
assertEquals(seekPosition, cursorPosition);
|
||||
const buf = new Uint8Array(6);
|
||||
file.readSync(buf);
|
||||
|
@ -501,10 +495,7 @@ unitTest({ perms: { read: true } }, async function seekCurrent(): Promise<
|
|||
// Skipping "ello "
|
||||
const seekPosition = 5;
|
||||
// seekPosition is relative to current cursor position after read
|
||||
const cursorPosition = await file.seek(
|
||||
seekPosition,
|
||||
Deno.SeekMode.SEEK_CURRENT
|
||||
);
|
||||
const cursorPosition = await file.seek(seekPosition, Deno.SeekMode.Current);
|
||||
assertEquals(seekPosition + 1, cursorPosition);
|
||||
const buf = new Uint8Array(6);
|
||||
await file.read(buf);
|
||||
|
@ -521,10 +512,7 @@ unitTest({ perms: { read: true } }, function seekSyncCurrent(): void {
|
|||
// Skipping "ello "
|
||||
const seekPosition = 5;
|
||||
// seekPosition is relative to current cursor position after read
|
||||
const cursorPosition = file.seekSync(
|
||||
seekPosition,
|
||||
Deno.SeekMode.SEEK_CURRENT
|
||||
);
|
||||
const cursorPosition = file.seekSync(seekPosition, Deno.SeekMode.Current);
|
||||
assertEquals(seekPosition + 1, cursorPosition);
|
||||
const buf = new Uint8Array(6);
|
||||
file.readSync(buf);
|
||||
|
@ -538,7 +526,7 @@ unitTest({ perms: { read: true } }, async function seekEnd(): Promise<void> {
|
|||
const file = await Deno.open(filename);
|
||||
const seekPosition = -6;
|
||||
// seek from end of file that has 12 chars, 12 - 6 = 6
|
||||
const cursorPosition = await file.seek(seekPosition, Deno.SeekMode.SEEK_END);
|
||||
const cursorPosition = await file.seek(seekPosition, Deno.SeekMode.End);
|
||||
assertEquals(6, cursorPosition);
|
||||
const buf = new Uint8Array(6);
|
||||
await file.read(buf);
|
||||
|
@ -552,7 +540,7 @@ unitTest({ perms: { read: true } }, function seekSyncEnd(): void {
|
|||
const file = Deno.openSync(filename);
|
||||
const seekPosition = -6;
|
||||
// seek from end of file that has 12 chars, 12 - 6 = 6
|
||||
const cursorPosition = file.seekSync(seekPosition, Deno.SeekMode.SEEK_END);
|
||||
const cursorPosition = file.seekSync(seekPosition, Deno.SeekMode.End);
|
||||
assertEquals(6, cursorPosition);
|
||||
const buf = new Uint8Array(6);
|
||||
file.readSync(buf);
|
||||
|
|
Loading…
Reference in a new issue