How to use the adm-zip/util/index.js.Constants function in adm-zip

To help you get started, we’ve selected a few adm-zip examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imlucas / lone / embed / admzip.js View on Github external
return compressedData;
                }
                var data = new Buffer(_entryHeader.size);
                data.fill(0);
                switch (_entryHeader.method) {
                  case Utils.Constants.STORED:
                    compressedData.copy(data);
                    if (!crc32OK(data)) {
                        if (async && callback) callback(data, Utils.Errors.BAD_CRC);
                        return Utils.Errors.BAD_CRC;
                    } else {
                        if (async && callback) callback(data);
                        return data;
                    }
                    break;
                  case Utils.Constants.DEFLATED:
                    var inflater = new Methods.Inflater(compressedData);
                    if (!async) {
                        inflater.inflate(data);
                        if (!crc32OK(data)) {
                            console.warn(Utils.Errors.BAD_CRC + " " + _entryName.toString());
                        }
                        return data;
                    } else {
                        inflater.inflateAsync(function(result) {
                            result.copy(data, 0);
                            if (crc32OK(data)) {
                                if (callback) callback(data, Utils.Errors.BAD_CRC);
                            } else {
                                if (callback) callback(data);
                            }
                        });
github imlucas / lone / embed / admzip.js View on Github external
module.exports = function(input, inputType) {
            var entryList = [], entryTable = {}, _comment = new Buffer(0), filename = "", fs = require("fs"), inBuffer = null, mainHeader = new Headers.MainHeader;
            if (inputType == Utils.Constants.FILE) {
                filename = input;
                inBuffer = fs.readFileSync(filename);
                readMainHeader();
            } else if (inputType == Utils.Constants.BUFFER) {
                inBuffer = input;
                readMainHeader();
            } else {}
            function readEntries() {
                entryTable = {};
                entryList = new Array(mainHeader.diskEntries);
                var index = mainHeader.offset;
                for (var i = 0; i < entryList.length; i++) {
                    var tmp = index, entry = new ZipEntry(inBuffer);
                    entry.header = inBuffer.slice(tmp, tmp += Utils.Constants.CENHDR);
                    entry.entryName = inBuffer.slice(tmp, tmp += entry.header.fileNameLength);
                    if (entry.header.extraLength) {
github imlucas / lone / embed / admzip.js View on Github external
function readEntries() {
                entryTable = {};
                entryList = new Array(mainHeader.diskEntries);
                var index = mainHeader.offset;
                for (var i = 0; i < entryList.length; i++) {
                    var tmp = index, entry = new ZipEntry(inBuffer);
                    entry.header = inBuffer.slice(tmp, tmp += Utils.Constants.CENHDR);
                    entry.entryName = inBuffer.slice(tmp, tmp += entry.header.fileNameLength);
                    if (entry.header.extraLength) {
                        entry.extra = inBuffer.slice(tmp, tmp += entry.header.extraLength);
                    }
                    if (entry.header.commentLength) entry.comment = inBuffer.slice(tmp, tmp + entry.header.commentLength);
                    index += entry.header.entryHeaderSize;
                    entryList[i] = entry;
                    entryTable[entry.entryName] = entry;
                }
            }
            function readMainHeader() {
github imlucas / lone / embed / admzip.js View on Github external
define("adm-zip/headers/mainHeader.js", function(require, module, exports, __dirname, __filename) {
        var Utils = require("adm-zip/util/index.js"), Constants = Utils.Constants;
        module.exports = function() {
            var _volumeEntries = 0, _totalEntries = 0, _size = 0, _offset = 0, _commentLength = 0;
            return {
                get diskEntries() {
                    return _volumeEntries;
                },
                set diskEntries(val) {
                    _volumeEntries = _totalEntries = val;
                },
                get totalEntries() {
                    return _totalEntries;
                },
                set totalEntries(val) {
                    _totalEntries = _volumeEntries = val;
                },
                get size() {
github imlucas / lone / embed / admzip.js View on Github external
function readMainHeader() {
                var i = inBuffer.length - Utils.Constants.ENDHDR, n = Math.max(0, i - 65535), endOffset = 0;
                for (i; i >= n; i--) {
                    if (inBuffer[i] != 80) continue;
                    if (inBuffer.readUInt32LE(i) == Utils.Constants.ENDSIG) {
                        endOffset = i;
                        break;
                    }
                }
                if (!endOffset) throw Utils.Errors.INVALID_FORMAT;
                mainHeader.loadFromBinary(inBuffer.slice(endOffset, endOffset + Utils.Constants.ENDHDR));
                if (mainHeader.commentLength) {
                    _comment = inBuffer.slice(endOffset + Utils.Constants.ENDHDR);
                }
                readEntries();
            }
            return {
github imlucas / lone / embed / admzip.js View on Github external
define("adm-zip/zipEntry.js", function(require, module, exports, __dirname, __filename) {
        var Utils = require("adm-zip/util/index.js"), Headers = require("adm-zip/headers/index.js"), Constants = Utils.Constants, Methods = require("adm-zip/methods/index.js");
        module.exports = function(input) {
            var _entryHeader = new Headers.EntryHeader, _entryName = new Buffer(0), _comment = new Buffer(0), _isDirectory = false, uncompressedData = null, _extra = new Buffer(0);
            function getCompressedDataFromZip() {
                if (!input || !Buffer.isBuffer(input)) {
                    return new Buffer(0);
                }
                _entryHeader.loadDataHeaderFromBinary(input);
                return input.slice(_entryHeader.realDataOffset, _entryHeader.realDataOffset + _entryHeader.compressedSize);
            }
            function crc32OK(data) {
                if (_entryHeader.flags & 8 != 8) {
                    if (Utils.crc32(data) != _entryHeader.crc) {
                        return false;
                    }
                } else {}
                return true;
github imlucas / lone / embed / admzip.js View on Github external
define("adm-zip/headers/entryHeader.js", function(require, module, exports, __dirname, __filename) {
        var Utils = require("adm-zip/util/index.js"), Constants = Utils.Constants;
        module.exports = function() {
            var _verMade = 10, _version = 10, _flags = 0, _method = 0, _time = 0, _crc = 0, _compressedSize = 0, _size = 0, _fnameLen = 0, _extraLen = 0, _comLen = 0, _diskStart = 0, _inattr = 0, _attr = 0, _offset = 0;
            var _dataHeader = {};
            function setTime(val) {
                var val = new Date(val);
                _time = (val.getFullYear() - 1980 & 127) << 25 | val.getMonth() + 1 << 21 | val.getDay() << 16 | val.getHours() << 11 | val.getMinutes() << 5 | val.getSeconds() >> 1;
            }
            setTime(+(new Date));
            return {
                get made() {
                    return _verMade;
                },
                set made(val) {
                    _verMade = val;
                },
                get version() {