What options are there to handle unzipping .zip files from within a Node.js script on Windows (XP)?
I'm working with the latest (at present) node.js v0.5.8 Windows node.exe.
Suggestions welcome.
-P.
I've found this zip library. It's very easy to install and use:
npm install zip
/* Only js dependencies, no local building needed */
from test.js
var z = require("zip");
var FS = require("fs");
var data = FS.readFileSync("test.zip")
var reader = z.Reader(data);
console.log(reader.toObject('utf-8'));
Provides also ways to iterate through the zip entries and getting data through Buffers.
ADM-ZIP is a pure JavaScript implementation for zip data compression for NodeJS.
Node provides support for the ZLIB library which should allow you to decompress a zip file using gzip: http://nodejs.org/docs/v0.5.8/api/zlib.html
Related
Using Laravel, I am trying to make a function which would download all files in a directory from S3.
I have used to retrieve all keys of the files using $file = Storage::disk('s3')->allFiles('path');, but I do not know what to do next.
It seems like I have to download all files into local, then zip those files, then download that zip file. I would like to know if there is a better way.
Any suggestion or advice would be appreciated.
I was able to do what I wanted with this:
http://coderaweso.me/zip-and-download-files-directory-from-amazon-s3-with-laravel/
It is not possible to send more than one file simultaneously over the same request with the HTTP protocol. Laravel also does not support this. You have to pack the files in, for example, a zip file.
Install Chumper/Zipper package and return a zip containing all your files:
$files = Storage::disk('s3')->allFiles('path');
Zipper::make(public_path('test.zip'))->add($files);
return response()->download(public_path('test.zip'));
I am using webpack and electron and while I can reference my script files fine locally (app/scripts/scriptname.sh), when it comes to the production deploy, I get an error: Can't open app/components/scripts/scriptname.sh.
It's unclear to me if this is an electron-dependent issue or a webpack-issue.
I am running these using node child_process as:
var ls = spawn('sh', ['app/components/scripts/scriptname.sh']);
I don't necessarily need the scripts to be in their own folder it would just be helpful.
You need to provide the complete absolute path to the script. To do that you can use the app.getAppPath() API of electron
app.getAppPath()
Returns String - The current application directory.
So your code would be something like:
var scriptAbsolutePath = app.getAppPath() + '/app/components/scripts/scriptname.sh';
var ls = spawn('sh', [scriptAbsolutePath]);
You can also have a look at app.getPath(name) API if it satisfies your particular requirement.
I am trying to unpack tar.xz file using gradle. First I download it and then unpack using tasks
def rootDir = project(":").projectDir
task downloadGHC(type: Download) {
src "$ghcDownloadLink"
dest new File("$rootDir/applications/install", "ghc-8.0.1-x86_64-unknown-mingw32.tar.xz")
onlyIfNewer true
}
task unpackGHC(dependsOn: downloadGHC, type: Copy) {
from tarTree(downloadGHC.dest)
into "$rootDir/applications/ghc"
}
But I get this error
Unable to expand TAR 'L:\...\applications\install\ghc-8.0.1-x86_64-unknown-mingw32.tar.xz'
The tar might be corrupted or it is compressed in an unexpected way.
By default the tar tree tries to guess the compression based on the file extension.
If you need to specify the compression explicitly please refer to the DSL reference.
> Error detected parsing the header
I am able to open the file so it is not corrupted. How to unpack it?
Since there is an error parsing the header, I suppose the tarTree() accepts only .tar files and not .tar.xz file. You can call an external program like tar from your gradle script to unpack the file.
Or you can write a small program to decompress the xz to tar using xz-java library (XZInputStream class).
I have developed my add-on in scratchpad environment and now developing is finished and I want to create final xpi file.
I replace only this:
Cu.import('resource://gre/modules/ctypes.jsm');
by this:
var {Cu} = require("chrome");
var{ctypes} = Cu.import("resource://gre/modules/ctypes.jsm", null);
Then using nodejs (jpm init and jpm xpi commands) I created xpi file however this is not worked properly.
What we did was follow the jpm tutorial: https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Getting_Started_%28jpm%29 and https://developer.mozilla.org/en-US/Add-ons/SDK/Tools/jpm#Installation
I did this on a Windows system:
we downloaded node.js
npm came with it
created a directory, in this directory i did jpm-init from command line
filled out the prompts then filled in the code for the addon:
We then created a similiar addon to this demo addon here:
https://github.com/Noitidart/jpm-chromeworker
I cant share the actuall addon as that was personal to the user. But the above is simpler and shows how to do it.
We did our jsctypes in a chromeworker, and have it communicate with index.js via messaging
How can I download and unpack ZIP file to extension folder?
Need to update my resources/config from ZIP package stored online.
Is this possible?
Please point me over to documentation or examples
Thanks
In Firefox 4+ you can get the directory of your extension like this:
Components.utils.import("resource://gre/modules/AddonManager.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
AddonManager.getAddonByID(extensionID, function(addon) {
var extensionDir =
Services.io.getProtocolHandler("file").QueryInterface(Ci.nsIFileProtocolHandler).
getFileFromURLSpec(addon.getResourceURI(null).spec);
}
To download the file from an extension, create an XMLHttpRequest using:
var xhr = Cc["#mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
You can read the ZIP file using the nsIZipReader XPCOM interface (see http://mxr.mozilla.org/mozilla-central/source/modules/libjar/nsIZipReader.idl). Instantiate the component like this:
var zipReader = Cc["#mozilla.org/libjar/zip-reader;1"].createInstance(Ci.nsIZipReader);