Skip to content

Commit

Permalink
reviewed API.md
Browse files Browse the repository at this point in the history
  • Loading branch information
bjouhier committed Feb 23, 2012
1 parent 00548df commit 8b66d2f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions API.md
@@ -1,12 +1,13 @@


# node-native-zip module # node-native-zip module


Simple API to create a zip archive. No extenal dependencies (except streamline.js) Simple API to create a zip archive. No external dependencies (except streamline.js).


* `archive = new zip.Zip(outStream, options)` * `archive = new zip.Zip(outStream[, options])`
Creates a zip archive. Creates a zip archive.
Uses _deflate_ compression by default. You can override this by passing Uses _deflate_ compression by default. You can override this by passing
options = { zipMethod: zip.store } `options = { zipMethod: zip.store }`

* `archive.add(_, entry)` * `archive.add(_, entry)`
Adds an entry to the archive. Adds an entry to the archive.
If the entry is `{ name: "...", path: "..." }`, If the entry is `{ name: "...", path: "..." }`,
Expand All @@ -17,12 +18,15 @@ Simple API to create a zip archive. No extenal dependencies (except streamline.j
If you pass a directory `path`, you can also pass a `filter` function in the entry. If you pass a directory `path`, you can also pass a `filter` function in the entry.
The `filter` function will be called as `filter(filename, parentEntry)`. The `filter` function will be called as `filter(filename, parentEntry)`.
You can also pass an array of entries instead of a single entry. You can also pass an array of entries instead of a single entry.

Returns `this` for chaining Returns `this` for chaining

* `archive.finish(_)` * `archive.finish(_)`
Writes the trailer at the end of the archive. Writes the trailer at the end of the archive.
Returns `this` for chaining. Returns `this` for chaining.

* `zipMethod: zip.store` * `zipMethod: zip.store`
_store_ method (no compression) _store_ method (no compression)

* `zipMethod: zip.deflate` * `zipMethod: zip.deflate`
_deflate_ method (standard compression) _deflate_ method (standard compression)

12 changes: 8 additions & 4 deletions janzip/janzip.js
Expand Up @@ -18,12 +18,13 @@ var zlib = require("zlib");
/// ///
/// # node-native-zip module /// # node-native-zip module
/// ///
/// Simple API to create a zip archive. No extenal dependencies (except streamline.js) /// Simple API to create a zip archive. No external dependencies (except streamline.js).
/// ///
/// * `archive = new zip.Zip(outStream, options)` /// * `archive = new zip.Zip(outStream[, options])`
/// Creates a zip archive. /// Creates a zip archive.
/// Uses _deflate_ compression by default. You can override this by passing /// Uses _deflate_ compression by default. You can override this by passing
/// options = { zipMethod: zip.store } /// `options = { zipMethod: zip.store }`
///
exports.Zip = function(outStream, options) { exports.Zip = function(outStream, options) {
// auto-wrap outStream with streamline stream // auto-wrap outStream with streamline stream
var os = outStream.emitter ? outStream : new streams.WritableStream(outStream); var os = outStream.emitter ? outStream : new streams.WritableStream(outStream);
Expand Down Expand Up @@ -126,8 +127,8 @@ exports.Zip = function(outStream, options) {
/// If you pass a directory `path`, you can also pass a `filter` function in the entry. /// If you pass a directory `path`, you can also pass a `filter` function in the entry.
/// The `filter` function will be called as `filter(filename, parentEntry)`. /// The `filter` function will be called as `filter(filename, parentEntry)`.
/// You can also pass an array of entries instead of a single entry. /// You can also pass an array of entries instead of a single entry.
///
/// Returns `this` for chaining /// Returns `this` for chaining
///
this.add = function(_, entry) { this.add = function(_, entry) {
if (Array.isArray(entry)) { if (Array.isArray(entry)) {
flows.each(_, entry, this.add.bind(this)); flows.each(_, entry, this.add.bind(this));
Expand Down Expand Up @@ -164,6 +165,7 @@ exports.Zip = function(outStream, options) {
/// * `archive.finish(_)` /// * `archive.finish(_)`
/// Writes the trailer at the end of the archive. /// Writes the trailer at the end of the archive.
/// Returns `this` for chaining. /// Returns `this` for chaining.
///
this.finish = function(_) { this.finish = function(_) {
var totalFileLength = fileOffset; var totalFileLength = fileOffset;


Expand Down Expand Up @@ -192,6 +194,7 @@ exports.Zip = function(outStream, options) {


/// * `zipMethod: zip.store` /// * `zipMethod: zip.store`
/// _store_ method (no compression) /// _store_ method (no compression)
///
exports.store = { exports.store = {
indicator: [0x00, 0x00], indicator: [0x00, 0x00],
compress: function(content, _) { compress: function(content, _) {
Expand All @@ -201,6 +204,7 @@ exports.store = {


/// * `zipMethod: zip.deflate` /// * `zipMethod: zip.deflate`
/// _deflate_ method (standard compression) /// _deflate_ method (standard compression)
///
exports.deflate = { exports.deflate = {
indicator: [0x08, 0x00], indicator: [0x08, 0x00],
compress: function(content, _) { compress: function(content, _) {
Expand Down

0 comments on commit 8b66d2f

Please sign in to comment.