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
113
114
115
116
|
/*
This file is part of libextractor.
(C) 2002, 2003, 2004, 2005, 2006, 2009, 2012 Vidyut Samanta and Christian Grothoff
libextractor is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, or (at your
option) any later version.
libextractor is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with libextractor; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/**
* @file main/extractor_datasource.h
* @brief random access and possibly decompression of data from buffer in memory or file on disk
* @author Christian Grothoff
*/
#ifndef EXTRACTOR_DATASOURCE_H
#define EXTRACTOR_DATASOURCE_H
#include "extractor.h"
/**
* Handle to a datasource we can use for the plugins.
*/
struct EXTRACTOR_Datasource;
/**
* Create a datasource from a file on disk.
*
* @param filename name of the file on disk
* @param proc metadata callback to call with meta data found upon opening
* @param proc_cls callback cls
* @return handle to the datasource, NULL on error
*/
struct EXTRACTOR_Datasource *
EXTRACTOR_datasource_create_from_file_ (const char *filename,
EXTRACTOR_MetaDataProcessor proc, void *proc_cls);
/**
* Create a datasource from a buffer in memory.
*
* @param buf data in memory
* @param size number of bytes in 'buf'
* @param proc metadata callback to call with meta data found upon opening
* @param proc_cls callback cls
* @return handle to the datasource, NULL on error
*/
struct EXTRACTOR_Datasource *
EXTRACTOR_datasource_create_from_buffer_ (const char *buf,
size_t size,
EXTRACTOR_MetaDataProcessor proc, void *proc_cls);
/**
* Destroy a data source.
*
* @param ds source to destroy
*/
void
EXTRACTOR_datasource_destroy_ (struct EXTRACTOR_Datasource *ds);
/**
* Make 'size' bytes of data from the data source available at 'data'.
*
* @param cls must be a 'struct EXTRACTOR_Datasource'
* @param data where the data should be copied to
* @param size maximum number of bytes requested
* @return number of bytes now available in data (can be smaller than 'size'),
* -1 on error
*/
ssize_t
EXTRACTOR_datasource_read_ (void *cls,
void *data,
size_t size);
/**
* Seek in the datasource. Use 'SEEK_CUR' for whence and 'pos' of 0 to
* obtain the current position in the file.
*
* @param cls must be a 'struct EXTRACTOR_Datasource'
* @param pos position to seek (see 'man lseek')o
* @param whence how to see (absolute to start, relative, absolute to end)
* @return new absolute position, -1 on error (i.e. desired position
* does not exist)
*/
int64_t
EXTRACTOR_datasource_seek_ (void *cls,
int64_t pos,
int whence);
/**
* Determine the overall size of the data source (after compression).
*
* @param cls must be a 'struct EXTRACTOR_Datasource'
* @param force force computing the size if it is unavailable
* @return overall file size, -1 on error or unknown
*/
int64_t
EXTRACTOR_datasource_get_size_ (void *cls,
int force);
#endif
|