File: file_name.md

package info (click to toggle)
node-jszip 3.5.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 25,100 kB
  • sloc: javascript: 5,652; makefile: 2; sh: 2
file content (49 lines) | stat: -rw-r--r-- 1,260 bytes parent folder | download | duplicates (4)
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
---
title: "file(name)"
layout: default
section: api
---

Get a file with the specified name. You can specify folders
in the name : the folder separator is a forward slash ("/").

__Returns__ : An instance of [ZipObject]({{site.baseurl}}/documentation/api_zipobject.html) representing
the file if any, `null` otherwise.

__Since__: v1.0.0

## Arguments

name | type   | description
-----|--------|-------------
name | string | the name of the file.

__Throws__ : Nothing.

<!-- __Complexity__ : This is a simple lookup in **O(1)**. -->

## Example

```js
var zip = new JSZip();
zip.file("file.txt", "content");

zip.file("file.txt").name // "file.txt"
zip.file("file.txt").async("string") // a promise of "content"
zip.file("file.txt").dir // false

// utf8 example
var zip = new JSZip();
zip.file("amount.txt", "€15");
zip.file("amount.txt").async("string") // a promise of "€15"
zip.file("amount.txt").async("arraybuffer") // a promise of an ArrayBuffer containing €15 encoded as utf8
zip.file("amount.txt").async("uint8array") // a promise of an Uint8Array containing €15 encoded as utf8

// with folders
zip.folder("sub").file("file.txt", "content");
zip.file("sub/file.txt"); // the file
// or
zip.folder("sub").file("file.txt") // the file
```