Rizin
unix-like reverse engineering framework and cli tools
zran.h
Go to the documentation of this file.
1
/* zran.h -- example of zlib/gzip stream indexing and random access
2
* Copyright (C) 2005, 2012, 2018 Mark Adler
3
* For conditions of distribution and use, see copyright notice in zlib.h
4
* Version 1.2 14 Oct 2018 Mark Adler */
5
6
#include <stdio.h>
7
#include "
zlib.h
"
8
9
/* Access point list. */
10
struct
deflate_index
{
11
int
have
;
/* number of list entries */
12
int
gzip
;
/* 1 if the index is of a gzip file, 0 if it is of a
13
zlib stream */
14
off_t
length
;
/* total length of uncompressed data */
15
void
*
list
;
/* allocated list of entries */
16
};
17
18
/* Make one entire pass through a zlib or gzip compressed stream and build an
19
index, with access points about every span bytes of uncompressed output.
20
gzip files with multiple members are indexed in their entirety. span should
21
be chosen to balance the speed of random access against the memory
22
requirements of the list, about 32K bytes per access point. The return value
23
is the number of access points on success (>= 1), Z_MEM_ERROR for out of
24
memory, Z_DATA_ERROR for an error in the input file, or Z_ERRNO for a file
25
read error. On success, *built points to the resulting index. */
26
int
deflate_index_build
(
FILE
*
in
,
off_t
span,
struct
deflate_index
**built);
27
28
/* Deallocate an index built by deflate_index_build() */
29
void
deflate_index_free
(
struct
deflate_index
*index);
30
31
/* Use the index to read len bytes from offset into buf. Return bytes read or
32
negative for error (Z_DATA_ERROR or Z_MEM_ERROR). If data is requested past
33
the end of the uncompressed data, then deflate_index_extract() will return a
34
value less than len, indicating how much was actually read into buf. This
35
function should not return a data error unless the file was modified since
36
the index was generated, since deflate_index_build() validated all of the
37
input. deflate_index_extract() will return Z_ERRNO if there is an error on
38
reading or seeking the input file. */
39
int
deflate_index_extract
(
FILE
*
in
,
struct
deflate_index
*index,
off_t
offset
,
40
unsigned
char
*
buf
,
int
len
);
len
size_t len
Definition:
6502dis.c:15
in
const lzma_allocator const uint8_t * in
Definition:
block.h:527
offset
voidpf uLong offset
Definition:
ioapi.h:144
buf
voidpf void * buf
Definition:
ioapi.h:138
benchmark.FILE
string FILE
Definition:
benchmark.py:21
off_t
int off_t
Definition:
sftypes.h:41
deflate_index
Definition:
zran.h:10
deflate_index::gzip
int gzip
Definition:
zran.h:12
deflate_index::have
int have
Definition:
zran.h:11
deflate_index::list
void * list
Definition:
zran.h:15
deflate_index::length
off_t length
Definition:
zran.h:14
zlib.h
deflate_index_free
void deflate_index_free(struct deflate_index *index)
Definition:
zran.c:76
deflate_index_extract
int deflate_index_extract(FILE *in, struct deflate_index *index, off_t offset, unsigned char *buf, int len)
Definition:
zran.c:248
deflate_index_build
int deflate_index_build(FILE *in, off_t span, struct deflate_index **built)
Definition:
zran.c:135
subprojects
zlib-1.2.12
examples
zran.h
Generated by
1.9.1