UNPKG

@astro-utils/forms

Version:

Server component for Astro (call server functions from client side with validation and state management)

29 lines (28 loc) 650 B
import { createReadStream } from "fs"; import { stat, copyFile } from "fs/promises"; export class BigFile { /** * @internal */ constructor(name, path, size) { this.name = name; this.path = path; this.size = size; } stream(options) { return createReadStream(this.path, options); } copyTo(destination) { return copyFile(this.path, destination); } /** * @internal */ static async loadFileSize(path) { const file = await stat(path); if (!file.isFile()) { throw new Error('Not a file'); } return file.size; } }