@versatiles/container
Version:
A client library for reading VersaTiles containers
20 lines (19 loc) • 1.47 kB
TypeScript
import type { Reader } from './interfaces.js';
/**
* Creates a file reader function for reading chunks of data from a file. This reader abstracts
* the file reading process and provides a simple async interface to read data from the specified file.
* The reader keeps the file open, hence it should be used in contexts where the file is not
* expected to be modified by other processes. It's important to manage the lifecycle of the file
* descriptor properly and ensure it's closed when no longer needed.
*
* @param {string} filename - The name of the file to read from. This file must exist and be readable,
* otherwise the function will throw an error when trying to open it.
* @returns {Reader} A reader function that when called, returns a promise. This promise resolves with a
* Buffer containing the read bytes from the file. The function reads `length` bytes of data
* from the file starting at `position`. If an error occurs during the read operation,
* the promise is rejected with the error. If `position` is beyond the end of the file,
* the promise resolves to an empty buffer. If the read operation attempts to read beyond
* the end of the file, the promise resolves with a buffer that contains only the bytes
* that could be read.
*/
export default function getFileReader(filename: string): Reader;