1 | //======================================================================== |
---|---|
2 | // |
3 | // FILECacheLoader.cc |
4 | // |
5 | // This file is licensed under the GPLv2 or later |
6 | // |
7 | // Copyright 2010 Hib Eris <hib@hiberis.nl> |
8 | // Copyright 2010, 2022 Albert Astals Cid <aacid@kde.org> |
9 | // Copyright 2010 Jonathan Liu <net147@gmail.com> |
10 | // Copyright 2021 Peter Williams <peter@newton.cx> |
11 | // Copyright 2021 Christian Persch <chpe@src.gnome.org> |
12 | // |
13 | //======================================================================== |
14 | |
15 | #include <config.h> |
16 | |
17 | #include "FILECacheLoader.h" |
18 | |
19 | #if defined(_WIN32) || defined(__CYGWIN__) |
20 | # include <fcntl.h> // for O_BINARY |
21 | # include <io.h> // for _setmode |
22 | #endif |
23 | |
24 | FILECacheLoader::~FILECacheLoader() |
25 | { |
26 | if (file != stdin) { |
27 | fclose(stream: file); |
28 | } |
29 | } |
30 | |
31 | size_t FILECacheLoader::init(CachedFile *cachedFile) |
32 | { |
33 | size_t read, size = 0; |
34 | char buf[CachedFileChunkSize]; |
35 | |
36 | #if defined(_WIN32) || defined(__CYGWIN__) |
37 | _setmode(fileno(file), O_BINARY); |
38 | #endif |
39 | |
40 | CachedFileWriter writer = CachedFileWriter(cachedFile, nullptr); |
41 | do { |
42 | read = fread(ptr: buf, size: 1, CachedFileChunkSize, stream: file); |
43 | (writer.write)(ptr: buf, CachedFileChunkSize); |
44 | size += read; |
45 | } while (read == CachedFileChunkSize); |
46 | |
47 | return size; |
48 | } |
49 | |
50 | int FILECacheLoader::load(const std::vector<ByteRange> &ranges, CachedFileWriter *writer) |
51 | { |
52 | return 0; |
53 | } |
54 |