This is the ZIP Unpacker extension used in Chrome OS to support reading and unpacking of zip archives.
Since the code is built with NaCl, you'll need its toolchain.
$ cd third-party $ make nacl_sdk
We'll use libraries from webports.
$ cd third-party $ make depot_tools $ make webports
First install npm using your normal packaging system. On Debian, you'll want something like:
$ sudo apt-get install npm
Then install the npm modules that we require. Do this in the root of the unpacker repo.
$ npm install bower 'vulcanize@<0.8'
Once done, install the libarchive-fork/ from third-party/ of the unpacker project. Note that you cannot use libarchive nor libarchive-dev packages from webports at this moment, as not all patches in the fork are upstreamed.
$ cd third-party $ make libarchive-fork
Polymer is used for UI. In order to fetch it, in the same directory type:
$ make polymer
Build the PNaCl module.
$ cd unpacker $ make [debug]
The package can be found in the release or debug directory. You can run it directly from there using Chrome's “Load unpacked extension” feature, or you can zip it up for posting to the Chrome Web Store.
$ zip -r release.zip release/
Once it's loaded, you should be able to open ZIP archives in the Files app.
Paths that aren't linked below are dynamically created at build time.
Some high level points to remember: the JS side reacts to user events and is the only part that has access to actual data on disk. It uses the NaCl module to do all the data parsing (e.g. gzip & tar), but it has to both send a request to the module (“parse this archive”), and respond to requests from the module when the module needs to read actual bytes on disk.
When the extension loads, background.js registers everything and goes idle.
When the Files app wants to mount an archive, callbacks in app.js
unpacker.app are called to initialize the NaCl runtime. Creates an
unpacker.Volume object for each mounted archive.
Requests on the archive (directory listing, metadata lookups, reading files) are routed through app.js
unpacker.app and to volume.js
unpacker.Volume. Then they are sent to the low level decompressor.js
unpacker.Decompressor which talks to the NaCl module using the request.js
unpacker.request protocol. Responses are passed back up.
When the NaCl module is loaded, module.cc
NaclArchiveModule is instantiated. That instantiates
NaclArchiveInstance for initial JS message entry points. It instantiates
Volume objects in turn use the volume_archive.h
VolumeArchive abstract interface to handle requests from the JS side (using the protocol defined in request.h
request:**). This way the lower levels don't have to deal with JS directly.
But NaCl code doesn't have access to any files or data itself. So the volume_reader.h
So requests (mount an archive, read a file, etc...) generally follow the path:
VolumeArchive has processed the raw data stream, it can return results to the
Volume object which takes care of posting JS status messages back to the Chrome side.
Here's the NaCl layout.
Volumeclass that encompasses a high level volume.
VolumeArchiveinterface for handling specific archive formats.
VolumeArchiveusing the libarchive project.
VolumeReaderinterface for low level reading of data.
To see debug messages open chrome from a terminal and check the output. For output redirection see https://developer.chrome.com/native-client/devguide/devcycle/debugging.