"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLocalOrRemoteStream = void 0;
const common_1 = require("./types/common");
const fs_1 = __importDefault(require("fs"));
const path_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;
