Spec-Zone.ru › Deno 1

Deno.seek

Искать идентификатор ресурса (rid) до заданного offset в режиме, заданном whence. Вызов разрешается до новой позиции внутри ресурса (байты с начала).

// Given file.rid pointing to file with "Hello world", which is 11 bytes long:
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.Start);
console.log(cursorPosition);  // 6
const buf = new Uint8Array(100);
await file.read(buf);
console.log(new TextDecoder().decode(buf)); // "world"
file.close();

Режимы поиска работают следующим образом:

// Given file.rid pointing to file with "Hello world", which is 11 bytes long:
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"));

// Seek 6 bytes from the start of the file
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.Current)); // "8"
// Seek backwards 2 bytes from the end of the file
console.log(await Deno.seek(file.rid, -2, Deno.SeekMode.End)); // "9" (e.g. 11-2)
file.close();
function seek(
rid: number,
offset: number,
whence: SeekMode,
): Promise<number>;
seek(rid: number, offset: number, whence: SeekMode): Promise<number>

Параметры

rid: number
offset: number
whence: SeekMode

Тип возвращаемого значения

Promise<number>

© 2018–2022 the Deno authors
https://doc.deno.land/deno/stable/~/Deno.seek

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API