UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

45 lines (44 loc) 2.04 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseRange = exports.getByteRange = void 0; const pfs = require("../../../util/misc/promisfied-fs"); function getByteRange(path, start, length) { return __awaiter(this, void 0, void 0, function* () { const fd = yield pfs.open(path, "r", null); try { const buffer = Buffer.alloc(length); const readResult = yield pfs.read(fd, buffer, 0, length, start); const result = []; for (let i = 0; i < readResult.bytesRead; i++) { result.push(buffer[i]); } return result; } finally { yield pfs.close(fd); } }); } exports.getByteRange = getByteRange; function parseRange(byteRange) { const separatorIndex = byteRange.indexOf("-"); if (separatorIndex === -1) { throw new Error(`Invalid byte range: "${byteRange}"`); } const start = parseInt(byteRange.substr(0, separatorIndex), 10); const end = parseInt(byteRange.substr(separatorIndex + 1, byteRange.length - separatorIndex - 1), 10); if (isNaN(start) || isNaN(end) || start < 0 || start > end) { throw new Error(`Invalid byte range: "${byteRange}"`); } return { start: start, length: end - start + 1 }; } exports.parseRange = parseRange;