libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

extractor_datasource.h (3791B)


      1 /*
      2      This file is part of libextractor.
      3      Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009, 2012 Vidyut Samanta and Christian Grothoff
      4 
      5      libextractor is free software; you can redistribute it and/or modify
      6      it under the terms of the GNU General Public License as published
      7      by the Free Software Foundation; either version 3, or (at your
      8      option) any later version.
      9 
     10      libextractor is distributed in the hope that it will be useful, but
     11      WITHOUT ANY WARRANTY; without even the implied warranty of
     12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13      General Public License for more details.
     14 
     15      You should have received a copy of the GNU General Public License
     16      along with libextractor; see the file COPYING.  If not, write to the
     17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18      Boston, MA 02110-1301, USA.
     19  */
     20 /**
     21  * @file main/extractor_datasource.h
     22  * @brief random access and possibly decompression of data from buffer in memory or file on disk
     23  * @author Christian Grothoff
     24  */
     25 #ifndef EXTRACTOR_DATASOURCE_H
     26 #define EXTRACTOR_DATASOURCE_H
     27 
     28 #include "extractor.h"
     29 
     30 /**
     31  * Handle to a datasource we can use for the plugins.
     32  */
     33 struct EXTRACTOR_Datasource;
     34 
     35 
     36 /**
     37  * Create a datasource from a file on disk.
     38  *
     39  * @param filename name of the file on disk
     40  * @param proc metadata callback to call with meta data found upon opening
     41  * @param proc_cls callback cls
     42  * @return handle to the datasource, NULL on error
     43  */
     44 struct EXTRACTOR_Datasource *
     45 EXTRACTOR_datasource_create_from_file_ (const char *filename,
     46                                         EXTRACTOR_MetaDataProcessor proc,
     47                                         void *proc_cls);
     48 
     49 
     50 /**
     51  * Create a datasource from a buffer in memory.
     52  *
     53  * @param buf data in memory
     54  * @param size number of bytes in 'buf'
     55  * @param proc metadata callback to call with meta data found upon opening
     56  * @param proc_cls callback cls
     57  * @return handle to the datasource, NULL on error
     58  */
     59 struct EXTRACTOR_Datasource *
     60 EXTRACTOR_datasource_create_from_buffer_ (const char *buf,
     61                                           size_t size,
     62                                           EXTRACTOR_MetaDataProcessor proc,
     63                                           void *proc_cls);
     64 
     65 
     66 /**
     67  * Destroy a data source.
     68  *
     69  * @param ds source to destroy
     70  */
     71 void
     72 EXTRACTOR_datasource_destroy_ (struct EXTRACTOR_Datasource *ds);
     73 
     74 
     75 /**
     76  * Make 'size' bytes of data from the data source available at 'data'.
     77  *
     78  * @param cls must be a 'struct EXTRACTOR_Datasource'
     79  * @param data where the data should be copied to
     80  * @param size maximum number of bytes requested
     81  * @return number of bytes now available in data (can be smaller than 'size'),
     82  *         -1 on error
     83  */
     84 ssize_t
     85 EXTRACTOR_datasource_read_ (void *cls,
     86                             void *data,
     87                             size_t size);
     88 
     89 
     90 /**
     91  * Seek in the datasource.  Use 'SEEK_CUR' for whence and 'pos' of 0 to
     92  * obtain the current position in the file.
     93  *
     94  * @param cls must be a 'struct EXTRACTOR_Datasource'
     95  * @param pos position to seek (see 'man lseek')o
     96  * @param whence how to see (absolute to start, relative, absolute to end)
     97  * @return new absolute position, -1 on error (i.e. desired position
     98  *         does not exist)
     99  */
    100 int64_t
    101 EXTRACTOR_datasource_seek_ (void *cls,
    102                             int64_t pos,
    103                             int whence);
    104 
    105 
    106 /**
    107  * Determine the overall size of the data source (after compression).
    108  *
    109  * @param cls must be a 'struct EXTRACTOR_Datasource'
    110  * @param force force computing the size if it is unavailable
    111  * @return overall file size, -1 on error or unknown
    112  */
    113 int64_t
    114 EXTRACTOR_datasource_get_size_ (void *cls,
    115                                 int force);
    116 
    117 
    118 #endif