File: Archive.rst

package info (click to toggle)
mupdf 1.27.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,224 kB
  • sloc: ansic: 335,320; python: 20,906; java: 7,520; javascript: 2,213; makefile: 1,152; xml: 675; cpp: 639; sh: 513; cs: 307; awk: 10; sed: 7; lisp: 3
file content (112 lines) | stat: -rw-r--r-- 2,456 bytes parent folder | download
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
.. default-domain:: js

.. highlight:: javascript

Archive
==============

|only_mutool|

Constructors
------------

.. class:: Archive(path)

	Create a new archive based either on a tar- or zip-file or the contents of a directory.

	:param string path: Path string to the archive file or directory.

	.. code-block::

		var archive1 = new mupdf.Archive("example1.zip")
		var archive2 = new mupdf.Archive("example2.tar")
		var archive3 = new mupdf.Archive("images/")

.. class:: Archive(buffer)

	Create a new archive based either on a tar- or zip-file contained in a buffer.

	:param Buffer | ArrayBuffer | Uint8Array | string buffer: Buffer containing a archive.

	.. code-block::

		var archive1 = new mupdf.Archive(fs.readFileSync("example1.zip"))
		var archive2 = new mupdf.Archive(fs.readFileSync("example1.tar"))

Instance methods
-----------------

.. method:: Archive.prototype.getFormat()

	Returns a string describing the archive format.

	:returns: string

	.. code-block::

		var archive = new mupdf.Archive("example1.zip")
		print(archive.getFormat())

.. method:: Archive.prototype.countEntries()

	Returns the number of entries in the archive.

	:returns: number

	.. code-block::

		var archive = new mupdf.Archive("example1.zip")
		var numEntries = archive.countEntries()

.. method:: Archive.prototype.listEntry(idx)

	Returns the name of entry number idx in the archive, or null if idx is
	out of range.

	:param number idx: Entry index.

	:returns: string | null

	.. code-block::

		var archive = new mupdf.Archive("example1.zip")
		var entry = archive.listEntry(0)

.. method:: Archive.prototype.hasEntry(name)

	Returns true if an entry of the given name exists in the archive.

	:param string name: Entry name to look for.

	:returns: boolean

	.. code-block::

		var archive = new mupdf.Archive("example1.zip")
		var hasEntry = archive.hasEntry("file1.txt")

.. method:: Archive.prototype.readEntry(name)

	Returns the contents of the entry of the given name.

	:param string name: Name of entry to look for.

	:returns: `Buffer`

	.. code-block::

		var archive = new mupdf.Archive("example1.zip")
		var contents = archive.readEntry("file1.txt")

Examples
--------

.. code-block::

		var archive = new mupdf.Archive("example1.zip")
		var n = archive.countEntries()
		for (var i = 0; i < n; ++i) {
			var entry = archive.listEntry(i)
			var contents = archive.readEntry(entry)
			console.log("entry", entry, contents.length)
		}