var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
    if (!privateMap.has(receiver)) {
        throw new TypeError("attempted to get private field on non-instance");
    }
    return privateMap.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
    if (!privateMap.has(receiver)) {
        throw new TypeError("attempted to set private field on non-instance");
    }
    privateMap.set(receiver, value);
    return value;
};
var _digest, _digestAlg;
export class BceFile {
    constructor(id, name, data) {
        _digest.set(this, void 0);
        _digestAlg.set(this, void 0);
        this.id = id;
        this.name = name;
        this.type = data.type;
        this.blob = data;
    }
    async hash(algorithm = 'SHA-256', output = 'hex') {
        if (!__classPrivateFieldGet(this, _digest) || __classPrivateFieldGet(this, _digestAlg) !== algorithm) {
            const data = await new Response(this.blob).arrayBuffer();
            const buffer = await crypto.subtle.digest(algorithm, data);
            __classPrivateFieldSet(this, _digestAlg, algorithm);
            __classPrivateFieldSet(this, _digest, Array.from(new Uint8Array(buffer)));
        }
        switch (output) {
            default:
            case 'array':
                return __classPrivateFieldGet(this, _digest);
            case 'hex':
                return __classPrivateFieldGet(this, _digest).map(b => b.toString(16).padStart(2, '0')).join('');
        }
    }
}
_digest = new WeakMap(), _digestAlg = new WeakMap();
