This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Bug 955999 - Running webapp-zip.js on node.js #28691
Merged
rickychien
merged 1 commit into
mozilla-b2g:master
from
rickychien:webapp-zip-to-nodejs
Mar 10, 2015
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -949,10 +949,9 @@ function Commander(cmd) { | |
process.init(_file); | ||
process.runw(true, args, args.length); | ||
callback && callback(process.exitValue); | ||
} catch (e) { | ||
} catch (err) { | ||
callback && callback(1); | ||
throw new Error('having trouble when execute ' + command + | ||
' ' + args.join(' ')); | ||
throw err; | ||
} | ||
|
||
processEvents(function () { | ||
|
@@ -1097,10 +1096,9 @@ function getDocument(content) { | |
* @param zip {nsIZipWriter} - the zip file | ||
* @param pathInZip {string} - the relative path to the new file | ||
* @param data {string} - the content of the file | ||
* @param time {string} - the timestamp of the file | ||
* @param compression {number} - the enum shows above | ||
*/ | ||
function addEntryContentWithTime(zip, pathInZip, data, time, compression) { | ||
function addFileToZip(zip, pathInZip, data, compression) { | ||
if (!data) { | ||
return; | ||
} | ||
|
@@ -1121,10 +1119,8 @@ function addEntryContentWithTime(zip, pathInZip, data, time, compression) { | |
input.init(data, -1, -1, 0); | ||
} | ||
|
||
zip.addEntryStream( | ||
pathInZip, time || 0, compression, input, false); | ||
zip.addEntryStream(pathInZip, Date.now() * 1000, compression, input, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the modification time of the entry in microseconds, so I think we don't need * 1000. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think so. but in fact I got correct time after * 1000 |
||
input.close(); | ||
|
||
} | ||
|
||
/** | ||
|
@@ -1140,6 +1136,10 @@ function getCompression(type) { | |
} | ||
} | ||
|
||
function hasFileInZip(zip, pathInZip) { | ||
return zip.hasEntry(pathInZip); | ||
} | ||
|
||
/** | ||
* Generate UUID. It's just a wrapper of 'nsIUUIDGenerator' | ||
* See the 'nsIUUIDGenerator' page on MDN. | ||
|
@@ -1176,23 +1176,23 @@ function copyRec(source, target) { | |
|
||
/** | ||
* Create an empty ZIP file. | ||
* For users, the way to read/write a ZIP file is | ||
* | ||
* 1. create an nsIZipWriter | ||
* 2. open it with the open method, which | ||
* 3. puts an nsIFile as the first argument | ||
* | ||
* For example: | ||
* | ||
* createZip().open(getFile(<some file>, <mode>)) | ||
* | ||
* @return {nsIZipWriter} | ||
*/ | ||
function createZip() { | ||
function createZip(zipPath) { | ||
var zip = Cc['@mozilla.org/zipwriter;1'].createInstance(Ci.nsIZipWriter); | ||
// PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE | ||
zip.open(getFile(zipPath), 0x04 | 0x08 | 0x20); | ||
return zip; | ||
} | ||
|
||
function closeZip(zip) { | ||
if (zip.alignStoredFiles) { | ||
zip.alignStoredFiles(4096); | ||
} | ||
zip.close(); | ||
} | ||
|
||
/** | ||
* Remove all listed files in the directory. | ||
* | ||
|
@@ -1250,7 +1250,7 @@ var scriptLoader = { | |
* Run specific build task on Node.js if RUN_ON_NODE is on, otherwise we go back | ||
* to XPCShell. | ||
*/ | ||
function NodeHelper(path) { | ||
function NodeHelper() { | ||
if (getEnv('RUN_ON_NODE') === '1') { | ||
var node = new Commander('node'); | ||
node.initPath(getEnvPath()); | ||
|
@@ -1260,7 +1260,7 @@ function NodeHelper(path) { | |
}; | ||
} else { | ||
this.require = function(path, options) { | ||
require(path).execute(options); | ||
return require(path).execute(options); | ||
}; | ||
} | ||
} | ||
|
@@ -1296,6 +1296,8 @@ exports.getOsType = getOsType; | |
exports.generateUUID = generateUUID; | ||
exports.copyRec = copyRec; | ||
exports.createZip = createZip; | ||
exports.closeZip = closeZip; | ||
exports.hasFileInZip = hasFileInZip; | ||
exports.scriptParser = Reflect.parse; | ||
exports.deleteFile = deleteFile; | ||
exports.listFiles = listFiles; | ||
|
@@ -1325,7 +1327,7 @@ exports.Services = Services; | |
exports.concatenatedScripts = concatenatedScripts; | ||
exports.dirname = dirname; | ||
exports.basename = basename; | ||
exports.addEntryContentWithTime = addEntryContentWithTime; | ||
exports.addFileToZip = addFileToZip; | ||
exports.getCompression = getCompression; | ||
exports.existsInAppDirs = existsInAppDirs; | ||
exports.removeFiles = removeFiles; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you refer to below link.
Stuk/jszip#194
It's no written in official document, so I append the link here.