Update JSON API
[src/app-framework-demo.git] / afm-client / bower_components / jszip / documentation / api_jszip / file_name.md
1 ---
2 title: "file(name)"
3 layout: default
4 section: api
5 ---
6
7 __Description__ : Get a file with the specified name. You can specify folders
8 in the name : the folder separator is a forward slash ("/").
9
10 __Arguments__
11
12 name | type   | description
13 -----|--------|-------------
14 name | string | the name of the file.
15
16 __Returns__ : An instance of [ZipObject]({{site.baseurl}}/documentation/api_zipobject.html) representing
17 the file if any, `null` otherwise.
18
19 __Throws__ : Nothing.
20
21 <!-- __Complexity__ : This is a simple lookup in **O(1)**. -->
22
23 __Examples__
24
25 ```js
26 var zip = new JSZip();
27 zip.file("file.txt", "content");
28
29 zip.file("file.txt").name // "file.txt"
30 zip.file("file.txt").asText() // "content"
31 zip.file("file.txt").options.dir // false
32
33 // utf8 example
34 var zip = new JSZip(zipFromAjaxWithUTF8);
35 zip.file("amount.txt").asText() // "€15"
36 zip.file("amount.txt").asArrayBuffer() // an ArrayBuffer containing €15 encoded as utf8
37 zip.file("amount.txt").asUint8Array() // an Uint8Array containing €15 encoded as utf8
38
39 // with folders
40 zip.folder("sub").file("file.txt", "content");
41 zip.file("sub/file.txt"); // the file
42 // or
43 zip.folder("sub").file("file.txt") // the file
44 ```
45
46