mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-05 19:42:15 +02:00
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
// TODO: allow over reading (returning a `Uint8Array`, an `offset` and a `length`) to avoid copying
|
|
|
|
import type { MaybePromiseLike } from "./utils.js";
|
|
|
|
export class ExactReadableEndedError extends Error {
|
|
constructor() {
|
|
super("ExactReadable ended");
|
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
}
|
|
}
|
|
|
|
export interface ExactReadable {
|
|
readonly position: number;
|
|
|
|
/**
|
|
* Read data from the underlying data source.
|
|
*
|
|
* The stream must return exactly `length` bytes or data. If that's not possible
|
|
* (due to end of file or other error condition), it must throw an {@link ExactReadableEndedError}.
|
|
*/
|
|
readExactly(length: number): Uint8Array;
|
|
}
|
|
|
|
export interface AsyncExactReadable {
|
|
readonly position: number;
|
|
|
|
/**
|
|
* Read data from the underlying data source.
|
|
*
|
|
* The stream must return exactly `length` bytes or data. If that's not possible
|
|
* (due to end of file or other error condition), it must throw an {@link ExactReadableEndedError}.
|
|
*/
|
|
readExactly(length: number): MaybePromiseLike<Uint8Array>;
|
|
}
|