"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLocalOrRemoteStream = void 0;
const tslib_1 = require("tslib");
const common_1 = require("./types/common");
const fs_1 = tslib_1.__importDefault(require("fs"));
const path_1 = tslib_1.__importDefault(require("path"));
async function getLocalOrRemoteStream(uri, out) {
    let stream;
    let totalBytes = 0;
    if ((0, common_1.isURL)(uri)) {
        const result = await (0, common_1.createRemoteStream)(uri);
        totalBytes = +(result.headers.get('Content-Length') || 0);
        stream = result.body;
    }
    else {
        const filename = path_1.default.isAbsolute(uri) ? uri : path_1.default.join(out, uri);
        totalBytes = fs_1.default.statSync(filename).size;
        stream = fs_1.default.createReadStream(filename);
    }
    return { totalBytes, stream };
}
exports.getLocalOrRemoteStream = getLocalOrRemoteStream;
