Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement breaking changes for JSZip v3. #253

Merged
merged 19 commits into from
Mar 22, 2016

Conversation

dduponchel
Copy link
Collaborator

This pull request implements most of the changes discussed in #224:

  • remove the defensive copy of zip.filter
  • remove deprecated API
  • type in generateAsync is now mandatory
  • change the createFolders default value from false to true
  • remove JSZip.compressions
  • add base64 support in async()
  • add a forEach method, use it in generate (to restrict content using JSZip.root)

It also add the related changes:

  • split the test/test.js file into test/asserts/*.js files
  • improve nodejs support
  • use UTC instead of the local timezone for dates

Regarding the nodejs support, I restricted the type to nodebuffer:
An object stream streaming blob/arraybuffer/uint8array/string is strange and
I don't know if it would be useful. I prefer disabling this feature and
wait for a real use case over this feature, finding out that that wasn't
a good idea and deprecate an awkward method.

This pull request is quite big, sorry. Each commit should be self-sufficient
and it may be easier to read them individually.

The filter method (reused by the file/folder method) created defensive
copies of every single item for each call. The idea was to prevent
people from updating the options or the data outside our API, but :

* that pointless because zip.files contains everything
* people already bypass that (see Stuk#20)
* this have a performance hit with many entries
* this behavior was never documented
This removes :

- options.base64 in generate()
- options.{base64,binary,dir,date} on ZipObject
- JSZip.utils
- JSZip#{crc32,utf8encode,utf8decode}

Lone survivor : JSZip.base64, because I don't know yet how to decode it
in the tests.
Calling `generate()` won't work anymore, the developer needs to specify an
output type.

"base64" was a nice default when the main way to provide a zip to a user
was to do:

    window.location = "data:application/zip;base64," + zip.generate({type:"base64"});

We now have better alternatives (saveAs, blob url, etc) that aren't
limited by the number of characters you can put in an url.
Change the createFolders default value from false to true. People are
used to file managers creating folders, the false value is (only ?)
needed when we don't generate a regular zip file (xlsx file for
example).
This commit does several things on the unit tests:

- upgrade QUnit 1.11 -> 1.20
- use qunit-cli instead of qunit (this let us use a recent version of QUnit)
- split the test/test.js file: we now have separated files in the
  test/asserts/ folder
- add the test files in the jshint list
- fix the indentation (3 spaces -> 4 spaces)
It will be easier to predict if the nodejs stream methods will fail.
Also update the error message to be less confusing server side ("not
supported by this platform" instead of "not supported by this browser").
While technically you can have a stream with an objectMode == true and
stream ArrayBuffers or unicode strings, asking for a type here is
overkill and error prone. Buffers are the best default value.
An object stream streaming blob/arraybuffer/uint8array/string is strange and
I don't know if it would be useful.

I prefer disabling this feature and wait for a real use case over
enabling this feature, finding out that that wasn't a good idea and
deprecate an awkward method.
If the ZipObject contains a nodejs stream or a worker, we will only be
able to read it once. This commit let the StreamHelper to "lock" a
worker chain to prevent further use.
We were lacking nodejs stream unit tests.
@dduponchel dduponchel mentioned this pull request Feb 10, 2016
@dduponchel
Copy link
Collaborator Author

The build fails in the generation of the dist/ files with node 0.10 (triggered by the gzip reporter of grunt-contrib-uglify). I'll look into the travis configuration to start the job test-browser only once (no need to build the dist/ files in every node version).
If that's not easy to do, removing the uglify reporter also fix the issue.

@dduponchel
Copy link
Collaborator Author

The build pass now.

On grunt-contrib-uglify, the `preserveComments: 'some'` option has some
issues. We can remove all comments but re-add the banner.
To get reproducible zip files, we need to use UTC instead of the local
timezone. That means my pc (Europe/Paris) and the test server (UTC)
should generate the same zip file.
This object now requires internal objects to work, exposing it is not
useful anymore.
The API was awkward (the `decode` function returned a binary string) and
base64 input/output provided by other methods should be enough.
It already worked, but now it is documented and tested.

Before that, people used `JSZip.base64` to encode binary contents.
The new forEach method is aware of the root folder level: it will only
show entries that start with `zip.root`.

When used in generate methods, it means the generated zip file will be
restricted to the current subfolder, fix Stuk#203.
This is the compagnion of 4950449, "[breaking change] Change the
createFolders default value". The previous commit didn't use the
default value for folders, this is now the case.
I forgot a file in 5fcfa93, here it is.
It uses a dependency which requires node >=0.12. On node 0.10 (used in the
travis builds) this reporter break the buid with a

    Object #<Object> has no method 'gzipSync'

This reporter needs the `--verbose` flag on grunt to display its
result, this commit won't change anything to the default output.
dduponchel added a commit that referenced this pull request Mar 22, 2016
Implement breaking changes for JSZip v3.
@dduponchel dduponchel merged commit 77fa193 into Stuk:jszip_v3 Mar 22, 2016
@dduponchel dduponchel deleted the breaking_changes branch March 22, 2016 20:42
@dduponchel dduponchel mentioned this pull request Apr 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant