File: getbinarycontent.md

package info (click to toggle)
node-jszip-utils 0.0.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 196 kB
  • sloc: makefile: 2; sh: 1
file content (62 lines) | stat: -rw-r--r-- 1,805 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
title: "getBinaryContent(path, callback)"
layout: default
section: api
---

__Description__ : Use an AJAX call to fetch a file (HTTP GET) on the server
that served the file. Cross domain requests will work if the browser support
[them](http://caniuse.com/cors) but only if the server send the
[right headers](https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS).
This function doesn't follow redirects : currently only `200 OK` are accepted.

__Arguments__

name     | type     | description
---------|----------|------------
path     | String   | the path to the resource to GET.
callback | function | the callback function.

The callback function has the following signature : `function (err, data) {...}` :


name | type               | description
-----|--------------------|------------
err  | Error              | the error, if any.
data | ArrayBuffer/String | the data in a format suitable for JSZip.

The data can be parsed by [JSZip#load](http://stuk.github.io/jszip/#doc_load_data_options)
or used with [JSZip#file](http://stuk.github.io/jszip/#doc_file_name_data_options)
to add a new file. With `JSZip#file` use `{binary:true}` as options.

__Returns__ : Nothing.

__Throws__ : Nothing.

<!--
__Complexity__ : **O(1)** everywhere but on IE <=9, **O(n)** on IE <=9, n being
the length of the fetched data.
-->

__Example__

```js
// loading a zip file
JSZipUtils.getBinaryContent("path/to/file.zip", function (err, data) {
   if(err) {
      throw err; // or handle the error
   }
   var zip = new JSZip(data);
});

// loading a file and add it in a zip file
JSZipUtils.getBinaryContent("path/to/picture.png", function (err, data) {
   if(err) {
      throw err; // or handle the error
   }
   var zip = new JSZip();
   zip.file("picture.png", data, {binary:true});
});
```