UNPKG

node-apk

Version:

A library to parse Android application manifest and signature

53 lines (52 loc) 1.94 kB
"use strict"; /* * Copyright (c) 2019 XdevL. All rights reserved. * * This work is licensed under the terms of the MIT license. * For a copy, see <https://opensource.org/licenses/MIT>. */ Object.defineProperty(exports, "__esModule", { value: true }); var stream_1 = require("stream"); var Source = /** @class */ (function () { function Source(buffer) { this.cursor = 0; this.buffer = buffer; } Source.prototype.readUByte = function () { return this.buffer.readUInt8(this.getCursorAndMove(1)); }; Source.prototype.readUShort = function () { return this.buffer.readUInt16LE(this.getCursorAndMove(2)); }; Source.prototype.readUInt = function () { return this.buffer.readUInt32LE(this.getCursorAndMove(4)); }; Source.prototype.readInt = function () { return this.buffer.readInt32LE(this.getCursorAndMove(4)); }; Source.prototype.readUtf8String = function (size) { return this.buffer.toString("utf8", this.getCursorAndMove(size), this.cursor); }; Source.prototype.readUtf16String = function (size) { return this.buffer.toString("ucs2", this.getCursorAndMove(size), this.cursor); }; Source.prototype.source = function (size) { return new Source(this.buffer.slice(this.getCursorAndMove(size), this.cursor)); }; Source.prototype.getCursorAndMove = function (offset) { this.cursor += offset; return this.cursor - offset; }; Source.prototype.moveAt = function (position) { this.getCursorAndMove(position - this.cursor); }; Source.prototype.stream = function (size) { var readable = new stream_1.Readable(); readable._read = function () { return undefined; }; readable.push(this.buffer.slice(this.cursor, this.cursor + size)); readable.push(null); return readable; }; return Source; }()); exports.default = Source;