Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
unarr.h
Go to the documentation of this file.
1 /* Copyright 2015 the unarr project authors (see AUTHORS file).
2  License: LGPLv3 */
3 
4 #ifndef unarr_h
5 #define unarr_h
6 
7 #include <stddef.h>
8 #include <stdint.h>
9 #include <stdbool.h>
10 typedef int64_t off64_t;
11 typedef int64_t time64_t;
12 
13 #define UNARR_API_VERSION 100
14 
15 /***** common/stream *****/
16 
17 typedef struct ar_stream_s ar_stream;
18 
19 /* opens a read-only stream for the given file path; returns NULL on error */
20 ar_stream *ar_open_file(const char *path);
21 #ifdef _WIN32
22 ar_stream *ar_open_file_w(const wchar_t *path);
23 #endif
24 /* opens a read-only stream for the given chunk of memory; the pointer must be valid until ar_close is called */
25 ar_stream *ar_open_memory(const void *data, size_t datalen);
26 #ifdef _WIN32
27 typedef struct IStream IStream;
28 /* opens a read-only stream based on the given IStream */
29 ar_stream *ar_open_istream(IStream *stream);
30 #endif
31 
32 /* closes the stream and releases underlying resources */
33 void ar_close(ar_stream *stream);
34 /* tries to read 'count' bytes into buffer, advancing the read offset pointer; returns the actual number of bytes read */
35 size_t ar_read(ar_stream *stream, void *buffer, size_t count);
36 /* moves the read offset pointer (same as fseek); returns false on failure */
37 bool ar_seek(ar_stream *stream, off64_t offset, int origin);
38 /* shortcut for ar_seek(stream, count, SEEK_CUR); returns false on failure */
39 bool ar_skip(ar_stream *stream, off64_t count);
40 /* returns the current read offset (or 0 on error) */
41 off64_t ar_tell(ar_stream *stream);
42 
43 /***** common/unarr *****/
44 
45 typedef struct ar_archive_s ar_archive;
46 
47 /* frees all data stored for the given archive; does not close the underlying stream */
49 /* reads the next archive entry; returns false on error or at the end of the file (use ar_at_eof to distinguish the two cases) */
50 bool ar_parse_entry(ar_archive *ar);
51 /* reads the archive entry at the given offset as returned by ar_entry_get_offset (offset 0 always restarts at the first entry); should always succeed */
52 bool ar_parse_entry_at(ar_archive *ar, off64_t offset);
53 /* reads the (first) archive entry associated with the given name; returns false if the entry couldn't be found */
54 bool ar_parse_entry_for(ar_archive *ar, const char *entry_name);
55 /* returns whether the last ar_parse_entry call has reached the file's expected end */
56 bool ar_at_eof(ar_archive *ar);
57 
58 /* returns the name of the current entry as UTF-8 string; this pointer is only valid until the next call to ar_parse_entry; returns NULL on failure */
59 const char *ar_entry_get_name(ar_archive *ar);
60 /* returns the stream offset of the current entry for use with ar_parse_entry_at */
62 /* returns the total size of uncompressed data of the current entry; read exactly that many bytes using ar_entry_uncompress */
63 size_t ar_entry_get_size(ar_archive *ar);
64 /* returns the stored modification date of the current entry in 100ns since 1601/01/01 */
66 /* WARNING: don't manually seek in the stream between ar_parse_entry and the last corresponding ar_entry_uncompress call! */
67 /* uncompresses the next 'count' bytes of the current entry into buffer; returns false on error */
68 bool ar_entry_uncompress(ar_archive *ar, void *buffer, size_t count);
69 
70 /* copies at most 'count' bytes of the archive's global comment (if any) into buffer; returns the actual amout of bytes copied (or, if 'buffer' is NULL, the required buffer size) */
71 size_t ar_get_global_comment(ar_archive *ar, void *buffer, size_t count);
72 
73 /***** rar/rar *****/
74 
75 /* checks whether 'stream' could contain RAR data and prepares for archive listing/extraction; returns NULL on failure */
77 
78 /***** tar/tar *****/
79 
80 /* checks whether 'stream' could contain TAR data and prepares for archive listing/extraction; returns NULL on failure */
82 
83 /***** zip/zip *****/
84 
85 /* checks whether 'stream' could contain ZIP data and prepares for archive listing/extraction; returns NULL on failure */
86 /* set deflatedonly for extracting XPS, EPUB, etc. documents where non-Deflate compression methods are not supported by specification */
87 ar_archive *ar_open_zip_archive(ar_stream *stream, bool deflatedonly);
88 
89 /***** _7z/_7z *****/
90 
91 /* checks whether 'stream' could contain 7Z data and prepares for archive listing/extraction; returns NULL on failure */
93 
94 #endif