Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

File specific compression settings. #42

Merged
merged 3 commits into from

2 participants

@amarcu5

I needed this feature for a project I was involved with. No point compressing files that are already compressed...

@dduponchel
Collaborator

Thanks for the pull request !

Could you add this in the documentation ? For the file(name) and file(name, data [,options]).

You also have an issue with the unit test unknown compression throws an exception : the exception is no longer thrown because the test JSZip object has no file.

@amarcu5

All fixed up.

@dduponchel dduponchel merged commit c91fe95 into Stuk:master
@dduponchel
Collaborator

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 27, 2013
  1. @amarcu5
Commits on Mar 29, 2013
  1. @amarcu5
  2. @amarcu5

    Added code to pass unit tests

    amarcu5 authored
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 6 deletions.
  1. +3 −1 index.html
  2. +12 −5 jszip.js
View
4 index.html
@@ -287,6 +287,7 @@ <h4 id="doc_file_name">file(name)</h4>
<li><code>binary</code>, boolean, cf <a href="#doc_file_name_data_options">file(name, data [,options])</a></li>
<li><code>dir</code>, boolean, true if this is a directory</li>
<li><code>date</code>, date, cf <a href="#doc_file_name_data_options">file(name, data [,options])</a></li>
+ <li><code>compression</code>, String, cf <a href="#doc_file_name_data_options">file(name, data [,options])</a></li>
</ul>
</li>
<li><code>asText()</code>, string, the content as an utf8 string (utf8 encoded if necessary).</li>
@@ -357,6 +358,7 @@ <h4 id="doc_file_name_data_options">file(name, data [,options])</h4>
UTF-8 characters will be encoded. If the data is an ArrayBuffer or an Uint8Array, this will be set to true.</li>
<li><code>date</code> (Date) use it to specify the last modification date.
If not set the current date is used.</li>
+ <li><code>compression</code> (String), default null. If set, specifies the file compression method to use. If not, the default file compression is used, cf <a href="#doc_generate_options">generate(options)</a>.</li>
<li><code>optimizedBinaryString</code> (boolean), default false. Set it to true if (and only if) the input
has already been prepared with a 0xFF mask.</li>
</ul>
@@ -443,7 +445,7 @@ <h4 id="doc_generate_options">generate(options)</h4>
<ul>
<li><code>base64</code> (boolean) <strong>deprecated</strong>, use "type" instead. <code>false</code> to get the result as a raw byte string.
Default : <code>true</code>, encode as base64.</li>
- <li><code>compression</code> (String) the compression method to use. <code>"STORE"</code> (no compression) by default,
+ <li><code>compression</code> (String) the default file compression method to use. <code>"STORE"</code> (no compression) by default,
you can use <code>"DEFLATE"</code> (include the file jszip-deflate.js) or write your own.</li>
<li><code>type</code> (String) the type of zip to return. The possible values are :
<ul>
View
17 jszip.js
@@ -53,7 +53,8 @@ JSZip.defaults = {
base64: false,
binary: false,
dir: false,
- date: null
+ date: null,
+ compression: null
};
@@ -170,6 +171,7 @@ JSZip.prototype = (function () {
}
o = extend(o, JSZip.defaults);
o.date = o.date || new Date();
+ if (o.compression !== null) o.compression = o.compression.toUpperCase();
return o;
};
@@ -292,7 +294,12 @@ JSZip.prototype = (function () {
dosDate = dosDate | o.date.getDate();
var hasData = data !== null && data.length !== 0;
-
+
+ compressionType = o.compression || compressionType;
+ if (!JSZip.compressions[compressionType]) {
+ throw compressionType + " is not a valid compression method !";
+ }
+
var compression = JSZip.compressions[compressionType];
var compressedData = hasData ? compression.compress(data) : '';
@@ -468,12 +475,12 @@ JSZip.prototype = (function () {
});
var compression = options.compression.toUpperCase();
- // The central directory, and files data
- var directory = [], files = [], fileOffset = 0;
-
if (!JSZip.compressions[compression]) {
throw compression + " is not a valid compression method !";
}
+
+ // The central directory, and files data
+ var directory = [], files = [], fileOffset = 0;
for (var name in this.files) {
if ( !this.files.hasOwnProperty(name) ) { continue; }
Something went wrong with that request. Please try again.