UNPKG

mindee

Version:

Mindee Client Library for Node.js

29 lines (28 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StreamInput = void 0; const localInputSource_1 = require("./localInputSource"); const inputSource_1 = require("./inputSource"); class StreamInput extends localInputSource_1.LocalInputSource { constructor({ inputStream, filename }) { super({ inputType: inputSource_1.INPUT_TYPE_STREAM, }); this.fileObject = Buffer.alloc(0); this.filename = filename; this.inputStream = inputStream; } async init() { this.fileObject = await this.stream2buffer(this.inputStream); this.mimeType = await this.checkMimetype(); } async stream2buffer(stream) { return new Promise((resolve, reject) => { const _buf = Array(); stream.on("data", (chunk) => _buf.push(chunk)); stream.on("end", () => resolve(Buffer.concat(_buf))); stream.on("error", (err) => reject(`Error converting stream - ${err}`)); }); } } exports.StreamInput = StreamInput;