2 * Copyright (c) 2004, Marcus Overhagen
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
22 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
23 * OF THE POSSIBILITY OF SUCH DAMAGE.
31 InputStream filecache
;
36 stream_read(struct InputStream
*cc
, ulonglong pos
, void *buffer
, int count
)
38 return reinterpret_cast<StreamIO
*>(cc
)->source
->ReadAt(pos
, buffer
, count
);
41 // Only needed if resync required.
43 stream_scan(struct InputStream
*cc
, ulonglong start
, unsigned signature
)
49 //stream_close(struct InputStream *cc)
54 // we might want to test against bytes remaining in file.
56 stream_getsize(struct InputStream
*cc
)
62 stream_geterror(struct InputStream
*cc
)
67 /* memory allocation */
69 stream_memalloc(struct InputStream
*cc
, size_t size
)
75 stream_memrealloc(struct InputStream
*cc
,void *mem
,size_t newsize
)
77 return realloc(mem
,newsize
);
81 stream_memfree(struct InputStream
*cc
, void *mem
)
86 // zero return causes parser to abort open
88 stream_progress(struct InputStream
*cc
, ulonglong cur
, ulonglong max
)
90 // no idea what this function is supposed to do.
95 CreateFileCache(BDataIO
*dataio
)
98 posio
= dynamic_cast<BPositionIO
*>(dataio
);
103 io
= (StreamIO
*)malloc(sizeof(StreamIO
));
107 io
->filecache
.read
= &stream_read
;
108 io
->filecache
.scan
= &stream_scan
;
109 // io->filecache.close = &stream_close;
110 io
->filecache
.getcachesize
= &stream_getsize
;
111 io
->filecache
.geterror
= &stream_geterror
;
112 io
->filecache
.memalloc
= &stream_memalloc
;
113 io
->filecache
.memrealloc
= &stream_memrealloc
;
114 io
->filecache
.memfree
= &stream_memfree
;
115 io
->filecache
.progress
= &stream_progress
;
118 return reinterpret_cast<InputStream
*>(io
);