UNPKG

mindee

Version:

Mindee Client Library for Node.js

25 lines (24 loc) 812 B
import { INPUT_TYPE_PATH } from "./inputSource.js"; import { LocalInputSource } from "./localInputSource.js"; import path from "path"; import { logger } from "../logger.js"; import { promises as fs } from "fs"; export class PathInput extends LocalInputSource { constructor({ inputPath }) { super({ inputType: INPUT_TYPE_PATH, }); this.fileObject = Buffer.alloc(0); this.inputPath = inputPath; this.filename = path.basename(this.inputPath); } async init() { if (this.initialized) { return; } logger.debug(`Loading from path: ${this.inputPath}`); this.fileObject = Buffer.from(await fs.readFile(this.inputPath)); this.mimeType = await this.checkMimetype(); this.initialized = true; } }