UNPKG

balena-sdk

Version:
28 lines (27 loc) 961 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.assetHelpers = void 0; const tslib_1 = require("tslib"); const mime_1 = require("mime"); const promises_1 = tslib_1.__importDefault(require("fs/promises")); exports.assetHelpers = { getMimeType: (filePath) => { var _a; return (_a = (0, mime_1.getType)(filePath)) !== null && _a !== void 0 ? _a : 'application/octet-stream'; }, getFileSize: async (filePath) => { const stats = await promises_1.default.stat(filePath); return stats.size; }, readFileChunk: async (filePath, offset, length) => { const fd = await promises_1.default.open(filePath, 'r'); try { const buffer = Buffer.alloc(length); const { bytesRead } = await fd.read(buffer, 0, length, offset); return buffer.subarray(0, bytesRead); } finally { await fd.close(); } }, };