"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Functional_1 = require("../../../../../Class/Functional");
const ArrayBuffer_1 = require("../../../../../wrap/ArrayBuffer");
const _ids_1 = require("../../../../_ids");
class ReadAsArrayBuffer extends Functional_1.Functional {
    constructor(system) {
        super({
            i: ['reader', 'file', 'opt'],
            o: ['array'],
        }, {
            input: {
                file: {
                    ref: true,
                },
                reader: {
                    ref: true,
                },
            },
            output: {
                array: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_READ_AS_ARRAY_BUFFER);
    }
    async f({ reader, file, opt }, done, fail) {
        const file_ = (await file.raw());
        let array_;
        try {
            array_ = await reader.readAsArrayBuffer(file_);
        }
        catch (err) {
            fail(err.message.toLowerCase());
            return;
        }
        const array = (0, ArrayBuffer_1.wrapArrayBuffer)(array_, this.__system);
        done({ array });
    }
}
exports.default = ReadAsArrayBuffer;
//# sourceMappingURL=index.js.map