Fixed issue with npm cache when adding browser
Project: http://git-wip-us.apache.org/repos/asf/cordova-browser/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-browser/commit/926681b8 Tree: http://git-wip-us.apache.org/repos/asf/cordova-browser/tree/926681b8 Diff: http://git-wip-us.apache.org/repos/asf/cordova-browser/diff/926681b8 Branch: refs/heads/master Commit: 926681b8e61693c26ec5e563f6cd1d8e441e42e9 Parents: 6effec3 Author: Suraj Pindoria <[email protected]> Authored: Tue Sep 9 13:18:47 2014 -0700 Committer: Suraj Pindoria <[email protected]> Committed: Tue Sep 9 13:18:47 2014 -0700 ---------------------------------------------------------------------- .gitignore | 1 - VERSION | 2 +- node_modules/.bin/shjs | 1 + .../adm-zip/.idea/scopes/scope_settings.xml | 5 + node_modules/adm-zip/MIT-LICENSE.txt | 21 + node_modules/adm-zip/README.md | 64 + node_modules/adm-zip/adm-zip.js | 404 ++++ node_modules/adm-zip/headers/entryHeader.js | 261 +++ node_modules/adm-zip/headers/index.js | 2 + node_modules/adm-zip/headers/mainHeader.js | 80 + node_modules/adm-zip/methods/deflater.js | 1578 +++++++++++++++ node_modules/adm-zip/methods/index.js | 2 + node_modules/adm-zip/methods/inflater.js | 448 +++++ node_modules/adm-zip/package.json | 41 + .../adm-zip/test/assets/attributes_test.zip | Bin 0 -> 4189 bytes .../attributes_test/New folder/hidden.txt | 17 + .../New folder/hidden_readonly.txt | 17 + .../attributes_test/New folder/readonly.txt | 17 + .../attributes_test/New folder/somefile.txt | 17 + .../attributes_test/asd/New Text Document.txt | 0 .../test/assets/attributes_test/blank file.txt | 0 node_modules/adm-zip/test/assets/fast.zip | Bin 0 -> 4194 bytes node_modules/adm-zip/test/assets/fastest.zip | Bin 0 -> 4194 bytes node_modules/adm-zip/test/assets/linux_arc.zip | Bin 0 -> 415 bytes node_modules/adm-zip/test/assets/maximum.zip | Bin 0 -> 4086 bytes node_modules/adm-zip/test/assets/normal.zip | Bin 0 -> 4170 bytes node_modules/adm-zip/test/assets/store.zip | Bin 0 -> 5878 bytes node_modules/adm-zip/test/assets/ultra.zip | Bin 0 -> 4086 bytes node_modules/adm-zip/test/index.js | 5 + node_modules/adm-zip/util/constants.js | 84 + node_modules/adm-zip/util/errors.js | 35 + node_modules/adm-zip/util/fattr.js | 84 + node_modules/adm-zip/util/index.js | 4 + node_modules/adm-zip/util/utils.js | 145 ++ node_modules/adm-zip/zipEntry.js | 224 +++ node_modules/adm-zip/zipFile.js | 311 +++ node_modules/shelljs/.documentup.json | 6 + node_modules/shelljs/.npmignore | 1 + node_modules/shelljs/.travis.yml | 5 + node_modules/shelljs/LICENSE | 26 + node_modules/shelljs/README.md | 513 +++++ node_modules/shelljs/bin/shjs | 51 + node_modules/shelljs/global.js | 3 + node_modules/shelljs/jshint.json | 4 + node_modules/shelljs/make.js | 48 + node_modules/shelljs/package.json | 46 + node_modules/shelljs/scripts/docs.js | 15 + node_modules/shelljs/scripts/run-tests.js | 50 + node_modules/shelljs/shell.js | 1901 ++++++++++++++++++ node_modules/shelljs/test/.npmignore | 2 + node_modules/shelljs/test/cat.js | 57 + node_modules/shelljs/test/cd.js | 64 + node_modules/shelljs/test/chmod.js | 81 + node_modules/shelljs/test/config.js | 50 + node_modules/shelljs/test/cp.js | 143 ++ node_modules/shelljs/test/dirs.js | 37 + node_modules/shelljs/test/echo.js | 50 + node_modules/shelljs/test/env.js | 19 + node_modules/shelljs/test/exec.js | 109 + node_modules/shelljs/test/find.js | 56 + node_modules/shelljs/test/grep.js | 59 + node_modules/shelljs/test/ls.js | 202 ++ node_modules/shelljs/test/make.js | 20 + node_modules/shelljs/test/mkdir.js | 79 + node_modules/shelljs/test/mv.js | 130 ++ node_modules/shelljs/test/popd.js | 118 ++ node_modules/shelljs/test/pushd.js | 228 +++ node_modules/shelljs/test/pwd.js | 28 + node_modules/shelljs/test/resources/a.txt | 11 + .../test/resources/chmod/a/b/c/.npmignore | 0 .../test/resources/chmod/b/a/b/.npmignore | 0 .../test/resources/chmod/c/a/b/.npmignore | 0 node_modules/shelljs/test/resources/chmod/file1 | 2 + node_modules/shelljs/test/resources/cp/a | 1 + node_modules/shelljs/test/resources/cp/b | 1 + node_modules/shelljs/test/resources/cp/dir_a/z | 1 + .../test/resources/cp/dir_b/dir_b_a/dir_b_a_a/z | 1 + .../test/resources/external/node_script.js | 2 + node_modules/shelljs/test/resources/file1 | 1 + node_modules/shelljs/test/resources/file1.js | 1 + node_modules/shelljs/test/resources/file1.txt | 1 + node_modules/shelljs/test/resources/file2 | 1 + node_modules/shelljs/test/resources/file2.js | 1 + node_modules/shelljs/test/resources/file2.txt | 1 + .../shelljs/test/resources/find/.hidden | 1 + node_modules/shelljs/test/resources/find/a | 1 + node_modules/shelljs/test/resources/find/b | 1 + .../shelljs/test/resources/find/dir1/a_dir1 | 1 + .../test/resources/find/dir1/dir11/a_dir11 | 1 + .../shelljs/test/resources/find/dir2/a_dir1 | 1 + .../shelljs/test/resources/issue44/main.js | 1 + .../shelljs/test/resources/ls/.hidden_dir/nada | 1 + .../shelljs/test/resources/ls/.hidden_file | 1 + .../test/resources/ls/a_dir/.hidden_dir/nada | 1 + .../shelljs/test/resources/ls/a_dir/b_dir/z | 1 + .../shelljs/test/resources/ls/a_dir/nada | 1 + node_modules/shelljs/test/resources/ls/file1 | 1 + node_modules/shelljs/test/resources/ls/file1.js | 1 + node_modules/shelljs/test/resources/ls/file2 | 1 + node_modules/shelljs/test/resources/ls/file2.js | 1 + .../filename(with)[chars$]^that.must+be-escaped | 1 + .../shelljs/test/resources/pushd/a/dummy | 1 + .../shelljs/test/resources/pushd/b/c/dummy | 1 + node_modules/shelljs/test/rm.js | 183 ++ node_modules/shelljs/test/sed.js | 58 + node_modules/shelljs/test/tempdir.js | 27 + node_modules/shelljs/test/test.js | 91 + node_modules/shelljs/test/to.js | 39 + node_modules/shelljs/test/which.js | 38 + package.json | 7 +- 110 files changed, 8554 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/926681b8/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index 9b18e14..ee4e98e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -node_modules/ npm-debug.log temp .DS_Store http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/926681b8/VERSION ---------------------------------------------------------------------- diff --git a/VERSION b/VERSION index 79d94e6..1545d96 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -MASTER +3.5.0 http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/926681b8/node_modules/.bin/shjs ---------------------------------------------------------------------- diff --git a/node_modules/.bin/shjs b/node_modules/.bin/shjs new file mode 120000 index 0000000..a044997 --- /dev/null +++ b/node_modules/.bin/shjs @@ -0,0 +1 @@ +../shelljs/bin/shjs \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/926681b8/node_modules/adm-zip/.idea/scopes/scope_settings.xml ---------------------------------------------------------------------- diff --git a/node_modules/adm-zip/.idea/scopes/scope_settings.xml b/node_modules/adm-zip/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..0d5175c --- /dev/null +++ b/node_modules/adm-zip/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ +<component name="DependencyValidationManager"> + <state> + <option name="SKIP_IMPORT_STATEMENTS" value="false" /> + </state> +</component> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/926681b8/node_modules/adm-zip/MIT-LICENSE.txt ---------------------------------------------------------------------- diff --git a/node_modules/adm-zip/MIT-LICENSE.txt b/node_modules/adm-zip/MIT-LICENSE.txt new file mode 100644 index 0000000..14c3ee5 --- /dev/null +++ b/node_modules/adm-zip/MIT-LICENSE.txt @@ -0,0 +1,21 @@ +Copyright (c) 2012 Another-D-Mention Software and other contributors, +http://www.another-d-mention.ro/ + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/926681b8/node_modules/adm-zip/README.md ---------------------------------------------------------------------- diff --git a/node_modules/adm-zip/README.md b/node_modules/adm-zip/README.md new file mode 100644 index 0000000..030fab8 --- /dev/null +++ b/node_modules/adm-zip/README.md @@ -0,0 +1,64 @@ +# ADM-ZIP for NodeJS + +ADM-ZIP is a pure JavaScript implementation for zip data compression for [NodeJS](http://nodejs.org/). + +# Installation + +With [npm](http://npmjs.org) do: + + $ npm install adm-zip + +## What is it good for? +The library allows you to: + +* decompress zip files directly to disk or in memory buffers +* compress files and store them to disk in .zip format or in compressed buffers +* update content of/add new/delete files from an existing .zip + +# Dependencies +There are no other nodeJS libraries that ADM-ZIP is dependent of + +# Examples + +## Basic usage +```javascript + + var AdmZip = require('adm-zip'); + + // reading archives + var zip = new AdmZip("./my_file.zip"); + var zipEntries = zip.getEntries(); // an array of ZipEntry records + + zipEntries.forEach(function(zipEntry) { + console.log(zipEntry.toString()); // outputs zip entries information + if (zipEntry.entryName == "my_file.txt") { + console.log(zipEntry.data.toString('utf8')); + } + }); + // outputs the content of some_folder/my_file.txt + console.log(zip.readAsText("some_folder/my_file.txt")); + // extracts the specified file to the specified location + zip.extractEntryTo(/*entry name*/"some_folder/my_file.txt", /*target path*/"/home/me/tempfolder", /*maintainEntryPath*/false, /*overwrite*/true); + // extracts everything + zip.extractAllTo(/*target path*/"/home/me/zipcontent/", /*overwrite*/true); + + + // creating archives + var zip = new AdmZip(); + + // add file directly + zip.addFile("test.txt", new Buffer("inner content of the file"), "entry comment goes here"); + // add local file + zip.addLocalFile("/home/me/some_picture.png"); + // get everything as a buffer + var willSendthis = zip.toBuffer(); + // or write everything to disk + zip.writeZip(/*target file name*/"/home/me/files.zip"); + + + // ... more examples in the wiki +``` + +For more detailed information please check out the [wiki](https://github.com/cthackers/adm-zip/wiki). + +[](http://travis-ci.org/cthackers/adm-zip) http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/926681b8/node_modules/adm-zip/adm-zip.js ---------------------------------------------------------------------- diff --git a/node_modules/adm-zip/adm-zip.js b/node_modules/adm-zip/adm-zip.js new file mode 100644 index 0000000..46595fc --- /dev/null +++ b/node_modules/adm-zip/adm-zip.js @@ -0,0 +1,404 @@ +var fs = require("fs"), + pth = require("path"); + +fs.existsSync = fs.existsSync || pth.existsSync; + +var ZipEntry = require("./zipEntry"), + ZipFile = require("./zipFile"), + Utils = require("./util"); + +module.exports = function(/*String*/input) { + var _zip = undefined, + _filename = ""; + + if (input && typeof input === "string") { // load zip file + if (fs.existsSync(input)) { + _filename = input; + _zip = new ZipFile(input, Utils.Constants.FILE); + } else { + throw Utils.Errors.INVALID_FILENAME; + } + } else if(input && Buffer.isBuffer(input)) { // load buffer + _zip = new ZipFile(input, Utils.Constants.BUFFER); + } else { // create new zip file + _zip = new ZipFile(null, Utils.Constants.NONE); + } + + function getEntry(/*Object*/entry) { + if (entry && _zip) { + var item; + // If entry was given as a file name + if (typeof entry === "string") + item = _zip.getEntry(entry); + // if entry was given as a ZipEntry object + if (typeof entry === "object" && entry.entryName != undefined && entry.header != undefined) + item = _zip.getEntry(entry.entryName); + + if (item) { + return item; + } + } + return null; + } + + return { + /** + * Extracts the given entry from the archive and returns the content as a Buffer object + * @param entry ZipEntry object or String with the full path of the entry + * + * @return Buffer or Null in case of error + */ + readFile : function(/*Object*/entry) { + var item = getEntry(entry); + return item && item.getData() || null; + }, + + /** + * Asynchronous readFile + * @param entry ZipEntry object or String with the full path of the entry + * @param callback + * + * @return Buffer or Null in case of error + */ + readFileAsync : function(/*Object*/entry, /*Function*/callback) { + var item = getEntry(entry); + if (item) { + item.getDataAsync(callback); + } else { + callback(null,"getEntry failed for:" + entry) + } + }, + + /** + * Extracts the given entry from the archive and returns the content as plain text in the given encoding + * @param entry ZipEntry object or String with the full path of the entry + * @param encoding Optional. If no encoding is specified utf8 is used + * + * @return String + */ + readAsText : function(/*Object*/entry, /*String - Optional*/encoding) { + var item = getEntry(entry); + if (item) { + var data = item.getData(); + if (data && data.length) { + return data.toString(encoding || "utf8"); + } + } + return ""; + }, + + /** + * Asynchronous readAsText + * @param entry ZipEntry object or String with the full path of the entry + * @param callback + * @param encoding Optional. If no encoding is specified utf8 is used + * + * @return String + */ + readAsTextAsync : function(/*Object*/entry, /*Function*/callback, /*String - Optional*/encoding) { + var item = getEntry(entry); + if (item) { + item.getDataAsync(function(data) { + if (data && data.length) { + callback(data.toString(encoding || "utf8")); + } else { + callback(""); + } + }) + } else { + callback(""); + } + }, + + /** + * Remove the entry from the file or the entry and all it's nested directories and files if the given entry is a directory + * + * @param entry + */ + deleteFile : function(/*Object*/entry) { // @TODO: test deleteFile + var item = getEntry(entry); + if (item) { + _zip.deleteEntry(item.entryName); + } + }, + + /** + * Adds a comment to the zip. The zip must be rewritten after adding the comment. + * + * @param comment + */ + addZipComment : function(/*String*/comment) { // @TODO: test addZipComment + _zip.comment = comment; + }, + + /** + * Returns the zip comment + * + * @return String + */ + getZipComment : function() { + return _zip.comment || ''; + }, + + /** + * Adds a comment to a specified zipEntry. The zip must be rewritten after adding the comment + * The comment cannot exceed 65535 characters in length + * + * @param entry + * @param comment + */ + addZipEntryComment : function(/*Object*/entry,/*String*/comment) { + var item = getEntry(entry); + if (item) { + item.comment = comment; + } + }, + + /** + * Returns the comment of the specified entry + * + * @param entry + * @return String + */ + getZipEntryComment : function(/*Object*/entry) { + var item = getEntry(entry); + if (item) { + return item.comment || ''; + } + return '' + }, + + /** + * Updates the content of an existing entry inside the archive. The zip must be rewritten after updating the content + * + * @param entry + * @param content + */ + updateFile : function(/*Object*/entry, /*Buffer*/content) { + var item = getEntry(entry); + if (item) { + item.setData(content); + } + }, + + /** + * Adds a file from the disk to the archive + * + * @param localPath + */ + addLocalFile : function(/*String*/localPath, /*String*/zipPath) { + if (fs.existsSync(localPath)) { + if(zipPath){ + zipPath=zipPath.split("\\").join("/"); + if(zipPath.charAt(zipPath.length - 1) != "/"){ + zipPath += "/"; + } + }else{ + zipPath=""; + } + var p = localPath.split("\\").join("/").split("/").pop(); + + this.addFile(zipPath+p, fs.readFileSync(localPath), "", 0) + } else { + throw Utils.Errors.FILE_NOT_FOUND.replace("%s", localPath); + } + }, + + /** + * Adds a local directory and all its nested files and directories to the archive + * + * @param localPath + */ + addLocalFolder : function(/*String*/localPath, /*String*/zipPath) { + if(zipPath){ + zipPath=zipPath.split("\\").join("/"); + if(zipPath.charAt(zipPath.length - 1) != "/"){ + zipPath += "/"; + } + }else{ + zipPath=""; + } + localPath = localPath.split("\\").join("/"); //windows fix + if (localPath.charAt(localPath.length - 1) != "/") + localPath += "/"; + + if (fs.existsSync(localPath)) { + + var items = Utils.findFiles(localPath), + self = this; + + if (items.length) { + items.forEach(function(path) { + var p = path.split("\\").join("/").replace(localPath, ""); //windows fix + if (p.charAt(p.length - 1) !== "/") { + self.addFile(zipPath+p, fs.readFileSync(path), "", 0) + } else { + self.addFile(zipPath+p, new Buffer(0), "", 0) + } + }); + } + } else { + throw Utils.Errors.FILE_NOT_FOUND.replace("%s", localPath); + } + }, + + /** + * Allows you to create a entry (file or directory) in the zip file. + * If you want to create a directory the entryName must end in / and a null buffer should be provided. + * Comment and attributes are optional + * + * @param entryName + * @param content + * @param comment + * @param attr + */ + addFile : function(/*String*/entryName, /*Buffer*/content, /*String*/comment, /*Number*/attr) { + var entry = new ZipEntry(); + entry.entryName = entryName; + entry.comment = comment || ""; + entry.attr = attr || 438; //0666; + if (entry.isDirectory && content.length) { + // throw Utils.Errors.DIRECTORY_CONTENT_ERROR; + } + entry.setData(content); + _zip.setEntry(entry); + }, + + /** + * Returns an array of ZipEntry objects representing the files and folders inside the archive + * + * @return Array + */ + getEntries : function() { + if (_zip) { + return _zip.entries; + } else { + return []; + } + }, + + /** + * Returns a ZipEntry object representing the file or folder specified by ``name``. + * + * @param name + * @return ZipEntry + */ + getEntry : function(/*String*/name) { + return getEntry(name); + }, + + /** + * Extracts the given entry to the given targetPath + * If the entry is a directory inside the archive, the entire directory and it's subdirectories will be extracted + * + * @param entry ZipEntry object or String with the full path of the entry + * @param targetPath Target folder where to write the file + * @param maintainEntryPath If maintainEntryPath is true and the entry is inside a folder, the entry folder + * will be created in targetPath as well. Default is TRUE + * @param overwrite If the file already exists at the target path, the file will be overwriten if this is true. + * Default is FALSE + * + * @return Boolean + */ + extractEntryTo : function(/*Object*/entry, /*String*/targetPath, /*Boolean*/maintainEntryPath, /*Boolean*/overwrite) { + overwrite = overwrite || false; + maintainEntryPath = typeof maintainEntryPath == "undefined" ? true : maintainEntryPath; + + var item = getEntry(entry); + if (!item) { + throw Utils.Errors.NO_ENTRY; + } + + var target = pth.resolve(targetPath, maintainEntryPath ? item.entryName : pth.basename(item.entryName)); + + if (item.isDirectory) { + target = pth.resolve(target, ".."); + var children = _zip.getEntryChildren(item); + children.forEach(function(child) { + if (child.isDirectory) return; + var content = child.getData(); + if (!content) { + throw Utils.Errors.CANT_EXTRACT_FILE; + } + Utils.writeFileTo(pth.resolve(targetPath, maintainEntryPath ? child.entryName : child.entryName.substr(item.entryName.length)), content, overwrite); + }); + return true; + } + + var content = item.getData(); + if (!content) throw Utils.Errors.CANT_EXTRACT_FILE; + + if (fs.existsSync(targetPath) && !overwrite) { + throw Utils.Errors.CANT_OVERRIDE; + } + Utils.writeFileTo(target, content, overwrite); + + return true; + }, + + /** + * Extracts the entire archive to the given location + * + * @param targetPath Target location + * @param overwrite If the file already exists at the target path, the file will be overwriten if this is true. + * Default is FALSE + */ + extractAllTo : function(/*String*/targetPath, /*Boolean*/overwrite) { + overwrite = overwrite || false; + if (!_zip) { + throw Utils.Errors.NO_ZIP; + } + + _zip.entries.forEach(function(entry) { + if (entry.isDirectory) { + Utils.makeDir(pth.resolve(targetPath, entry.entryName.toString())); + return; + } + var content = entry.getData(); + if (!content) { + throw Utils.Errors.CANT_EXTRACT_FILE + "2"; + } + Utils.writeFileTo(pth.resolve(targetPath, entry.entryName.toString()), content, overwrite); + }) + }, + + /** + * Writes the newly created zip file to disk at the specified location or if a zip was opened and no ``targetFileName`` is provided, it will overwrite the opened zip + * + * @param targetFileName + * @param callback + */ + writeZip : function(/*String*/targetFileName, /*Function*/callback) { + if (arguments.length == 1) { + if (typeof targetFileName == "function") { + callback = targetFileName; + targetFileName = ""; + } + } + + if (!targetFileName && _filename) { + targetFileName = _filename; + } + if (!targetFileName) return; + + var zipData = _zip.compressToBuffer(); + if (zipData) { + Utils.writeFileTo(targetFileName, zipData, true); + } + }, + + /** + * Returns the content of the entire zip file as a Buffer object + * + * @return Buffer + */ + toBuffer : function(/*Function*/onSuccess,/*Function*/onFail,/*Function*/onItemStart,/*Function*/onItemEnd) { + this.valueOf = 2; + if (typeof onSuccess == "function") { + _zip.toAsyncBuffer(onSuccess,onFail,onItemStart,onItemEnd); + return null; + } + return _zip.compressToBuffer() + } + } +}; http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/926681b8/node_modules/adm-zip/headers/entryHeader.js ---------------------------------------------------------------------- diff --git a/node_modules/adm-zip/headers/entryHeader.js b/node_modules/adm-zip/headers/entryHeader.js new file mode 100644 index 0000000..a29c70f --- /dev/null +++ b/node_modules/adm-zip/headers/entryHeader.js @@ -0,0 +1,261 @@ +var Utils = require("../util"), + Constants = Utils.Constants; + +/* The central directory file header */ +module.exports = function () { + var _verMade = 0x0A, + _version = 0x0A, + _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 & 0x7f) << 25 // b09-16 years from 1980 + | (val.getMonth() + 1) << 21 // b05-08 month + | val.getDay() << 16 // b00-04 hour + + // 2 bytes time + | val.getHours() << 11 // b11-15 hour + | val.getMinutes() << 5 // b05-10 minute + | val.getSeconds() >> 1; // b00-04 seconds divided by 2 + } + + setTime(+new Date()); + + return { + get made () { return _verMade; }, + set made (val) { _verMade = val; }, + + get version () { return _version; }, + set version (val) { _version = val }, + + get flags () { return _flags }, + set flags (val) { _flags = val; }, + + get method () { return _method; }, + set method (val) { _method = val; }, + + get time () { return new Date( + ((_time >> 25) & 0x7f) + 1980, + ((_time >> 21) & 0x0f) - 1, + (_time >> 16) & 0x1f, + (_time >> 11) & 0x1f, + (_time >> 5) & 0x3f, + (_time & 0x1f) << 1 + ); + }, + set time (val) { + setTime(val); + }, + + get crc () { return _crc; }, + set crc (val) { _crc = val; }, + + get compressedSize () { return _compressedSize; }, + set compressedSize (val) { _compressedSize = val; }, + + get size () { return _size; }, + set size (val) { _size = val; }, + + get fileNameLength () { return _fnameLen; }, + set fileNameLength (val) { _fnameLen = val; }, + + get extraLength () { return _extraLen }, + set extraLength (val) { _extraLen = val; }, + + get commentLength () { return _comLen }, + set commentLength (val) { _comLen = val }, + + get diskNumStart () { return _diskStart }, + set diskNumStart (val) { _diskStart = val }, + + get inAttr () { return _inattr }, + set inAttr (val) { _inattr = val }, + + get attr () { return _attr }, + set attr (val) { _attr = val }, + + get offset () { return _offset }, + set offset (val) { _offset = val }, + + get encripted () { return (_flags & 1) == 1 }, + + get entryHeaderSize () { + return Constants.CENHDR + _fnameLen + _extraLen + _comLen; + }, + + get realDataOffset () { + return _offset + Constants.LOCHDR + _dataHeader.fnameLen + _dataHeader.extraLen; + }, + + get dataHeader () { + return _dataHeader; + }, + + loadDataHeaderFromBinary : function(/*Buffer*/input) { + var data = input.slice(_offset, _offset + Constants.LOCHDR); + // 30 bytes and should start with "PK\003\004" + if (data.readUInt32LE(0) != Constants.LOCSIG) { + throw Utils.Errors.INVALID_LOC; + } + _dataHeader = { + // version needed to extract + version : data.readUInt16LE(Constants.LOCVER), + // general purpose bit flag + flags : data.readUInt16LE(Constants.LOCFLG), + // compression method + method : data.readUInt16LE(Constants.LOCHOW), + // modification time (2 bytes time, 2 bytes date) + time : data.readUInt32LE(Constants.LOCTIM), + // uncompressed file crc-32 value + crc : data.readUInt32LE(Constants.LOCCRC), + // compressed size + compressedSize : data.readUInt32LE(Constants.LOCSIZ), + // uncompressed size + size : data.readUInt32LE(Constants.LOCLEN), + // filename length + fnameLen : data.readUInt16LE(Constants.LOCNAM), + // extra field length + extraLen : data.readUInt16LE(Constants.LOCEXT) + } + }, + + loadFromBinary : function(/*Buffer*/data) { + // data should be 46 bytes and start with "PK 01 02" + if (data.length != Constants.CENHDR || data.readUInt32LE(0) != Constants.CENSIG) { + throw Utils.Errors.INVALID_CEN; + } + // version made by + _verMade = data.readUInt16LE(Constants.CENVEM); + // version needed to extract + _version = data.readUInt16LE(Constants.CENVER); + // encrypt, decrypt flags + _flags = data.readUInt16LE(Constants.CENFLG); + // compression method + _method = data.readUInt16LE(Constants.CENHOW); + // modification time (2 bytes time, 2 bytes date) + _time = data.readUInt32LE(Constants.CENTIM); + // uncompressed file crc-32 value + _crc = data.readUInt32LE(Constants.CENCRC); + // compressed size + _compressedSize = data.readUInt32LE(Constants.CENSIZ); + // uncompressed size + _size = data.readUInt32LE(Constants.CENLEN); + // filename length + _fnameLen = data.readUInt16LE(Constants.CENNAM); + // extra field length + _extraLen = data.readUInt16LE(Constants.CENEXT); + // file comment length + _comLen = data.readUInt16LE(Constants.CENCOM); + // volume number start + _diskStart = data.readUInt16LE(Constants.CENDSK); + // internal file attributes + _inattr = data.readUInt16LE(Constants.CENATT); + // external file attributes + _attr = data.readUInt32LE(Constants.CENATX); + // LOC header offset + _offset = data.readUInt32LE(Constants.CENOFF); + }, + + dataHeaderToBinary : function() { + // LOC header size (30 bytes) + var data = new Buffer(Constants.LOCHDR); + // "PK\003\004" + data.writeUInt32LE(Constants.LOCSIG, 0); + // version needed to extract + data.writeUInt16LE(_version, Constants.LOCVER); + // general purpose bit flag + data.writeUInt16LE(_flags, Constants.LOCFLG); + // compression method + data.writeUInt16LE(_method, Constants.LOCHOW); + // modification time (2 bytes time, 2 bytes date) + data.writeUInt32LE(_time, Constants.LOCTIM); + // uncompressed file crc-32 value + data.writeUInt32LE(_crc, Constants.LOCCRC); + // compressed size + data.writeUInt32LE(_compressedSize, Constants.LOCSIZ); + // uncompressed size + data.writeUInt32LE(_size, Constants.LOCLEN); + // filename length + data.writeUInt16LE(_fnameLen, Constants.LOCNAM); + // extra field length + data.writeUInt16LE(_extraLen, Constants.LOCEXT); + return data; + }, + + entryHeaderToBinary : function() { + // CEN header size (46 bytes) + var data = new Buffer(Constants.CENHDR + _fnameLen + _extraLen + _comLen); + // "PK\001\002" + data.writeUInt32LE(Constants.CENSIG, 0); + // version made by + data.writeUInt16LE(_verMade, Constants.CENVEM); + // version needed to extract + data.writeUInt16LE(_version, Constants.CENVER); + // encrypt, decrypt flags + data.writeUInt16LE(_flags, Constants.CENFLG); + // compression method + data.writeUInt16LE(_method, Constants.CENHOW); + // modification time (2 bytes time, 2 bytes date) + data.writeUInt32LE(_time, Constants.CENTIM); + // uncompressed file crc-32 value + data.writeInt32LE(_crc, Constants.CENCRC, true); + // compressed size + data.writeUInt32LE(_compressedSize, Constants.CENSIZ); + // uncompressed size + data.writeUInt32LE(_size, Constants.CENLEN); + // filename length + data.writeUInt16LE(_fnameLen, Constants.CENNAM); + // extra field length + data.writeUInt16LE(_extraLen, Constants.CENEXT); + // file comment length + data.writeUInt16LE(_comLen, Constants.CENCOM); + // volume number start + data.writeUInt16LE(_diskStart, Constants.CENDSK); + // internal file attributes + data.writeUInt16LE(_inattr, Constants.CENATT); + // external file attributes + data.writeUInt32LE(_attr, Constants.CENATX); + // LOC header offset + data.writeUInt32LE(_offset, Constants.CENOFF); + // fill all with + data.fill(0x00, Constants.CENHDR); + return data; + }, + + toString : function() { + return '{\n' + + '\t"made" : ' + _verMade + ",\n" + + '\t"version" : ' + _version + ",\n" + + '\t"flags" : ' + _flags + ",\n" + + '\t"method" : ' + Utils.methodToString(_method) + ",\n" + + '\t"time" : ' + _time + ",\n" + + '\t"crc" : 0x' + _crc.toString(16).toUpperCase() + ",\n" + + '\t"compressedSize" : ' + _compressedSize + " bytes,\n" + + '\t"size" : ' + _size + " bytes,\n" + + '\t"fileNameLength" : ' + _fnameLen + ",\n" + + '\t"extraLength" : ' + _extraLen + " bytes,\n" + + '\t"commentLength" : ' + _comLen + " bytes,\n" + + '\t"diskNumStart" : ' + _diskStart + ",\n" + + '\t"inAttr" : ' + _inattr + ",\n" + + '\t"attr" : ' + _attr + ",\n" + + '\t"offset" : ' + _offset + ",\n" + + '\t"entryHeaderSize" : ' + (Constants.CENHDR + _fnameLen + _extraLen + _comLen) + " bytes\n" + + '}'; + } + } +}; http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/926681b8/node_modules/adm-zip/headers/index.js ---------------------------------------------------------------------- diff --git a/node_modules/adm-zip/headers/index.js b/node_modules/adm-zip/headers/index.js new file mode 100644 index 0000000..b8c67b9 --- /dev/null +++ b/node_modules/adm-zip/headers/index.js @@ -0,0 +1,2 @@ +exports.EntryHeader = require("./entryHeader"); +exports.MainHeader = require("./mainHeader"); http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/926681b8/node_modules/adm-zip/headers/mainHeader.js ---------------------------------------------------------------------- diff --git a/node_modules/adm-zip/headers/mainHeader.js b/node_modules/adm-zip/headers/mainHeader.js new file mode 100644 index 0000000..002bc8a --- /dev/null +++ b/node_modules/adm-zip/headers/mainHeader.js @@ -0,0 +1,80 @@ +var Utils = require("../util"), + Constants = Utils.Constants; + +/* The entries in the end of central directory */ +module.exports = function () { + var _volumeEntries = 0, + _totalEntries = 0, + _size = 0, + _offset = 0, + _commentLength = 0; + + return { + get diskEntries () { return _volumeEntries }, + set diskEntries (/*Number*/val) { _volumeEntries = _totalEntries = val; }, + + get totalEntries () { return _totalEntries }, + set totalEntries (/*Number*/val) { _totalEntries = _volumeEntries = val; }, + + get size () { return _size }, + set size (/*Number*/val) { _size = val; }, + + get offset () { return _offset }, + set offset (/*Number*/val) { _offset = val; }, + + get commentLength () { return _commentLength }, + set commentLength (/*Number*/val) { _commentLength = val; }, + + get mainHeaderSize () { + return Constants.ENDHDR + _commentLength; + }, + + loadFromBinary : function(/*Buffer*/data) { + // data should be 22 bytes and start with "PK 05 06" + if (data.length != Constants.ENDHDR || data.readUInt32LE(0) != Constants.ENDSIG) + throw Utils.Errors.INVALID_END; + + // number of entries on this volume + _volumeEntries = data.readUInt16LE(Constants.ENDSUB); + // total number of entries + _totalEntries = data.readUInt16LE(Constants.ENDTOT); + // central directory size in bytes + _size = data.readUInt32LE(Constants.ENDSIZ); + // offset of first CEN header + _offset = data.readUInt32LE(Constants.ENDOFF); + // zip file comment length + _commentLength = data.readUInt16LE(Constants.ENDCOM); + }, + + toBinary : function() { + var b = new Buffer(Constants.ENDHDR + _commentLength); + // "PK 05 06" signature + b.writeUInt32LE(Constants.ENDSIG, 0); + b.writeUInt32LE(0, 4); + // number of entries on this volume + b.writeUInt16LE(_volumeEntries, Constants.ENDSUB); + // total number of entries + b.writeUInt16LE(_totalEntries, Constants.ENDTOT); + // central directory size in bytes + b.writeUInt32LE(_size, Constants.ENDSIZ); + // offset of first CEN header + b.writeUInt32LE(_offset, Constants.ENDOFF); + // zip file comment length + b.writeUInt16LE(_commentLength, Constants.ENDCOM); + // fill comment memory with spaces so no garbage is left there + b.fill(" ", Constants.ENDHDR); + + return b; + }, + + toString : function() { + return '{\n' + + '\t"diskEntries" : ' + _volumeEntries + ",\n" + + '\t"totalEntries" : ' + _totalEntries + ",\n" + + '\t"size" : ' + _size + " bytes,\n" + + '\t"offset" : 0x' + _offset.toString(16).toUpperCase() + ",\n" + + '\t"commentLength" : 0x' + _commentLength + "\n" + + '}'; + } + } +}; \ No newline at end of file
