blob: d2d8d2a13d4a4343bc5acadb263e1a5c0b83bd09 (
plain)
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
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_CHUNK_STREAM_H_
#define PDF_CHUNK_STREAM_H_
#include <stddef.h>
#include <map>
#include <utility>
#include <vector>
namespace chrome_pdf {
// This class collects a chunks of data into one data stream. Client can check
// if data in certain range is available, and get missing chunks of data.
class ChunkStream {
public:
ChunkStream();
~ChunkStream();
void Clear();
void Preallocate(size_t stream_size);
size_t GetSize() const;
bool WriteData(size_t offset, void* buffer, size_t size);
bool ReadData(size_t offset, size_t size, void* buffer) const;
// Returns vector of pairs where first is an offset, second is a size.
bool GetMissedRanges(size_t offset, size_t size,
std::vector<std::pair<size_t, size_t> >* ranges) const;
bool IsRangeAvailable(size_t offset, size_t size) const;
size_t GetFirstMissingByte() const;
// Finds the first byte of the missing byte interval that offset belongs to.
size_t GetFirstMissingByteInInterval(size_t offset) const;
// Returns the last byte of the missing byte interval that offset belongs to.
size_t GetLastMissingByteInInterval(size_t offset) const;
private:
std::vector<unsigned char> data_;
// Pair, first - begining of the chunk, second - size of the chunk.
std::map<size_t, size_t> chunks_;
size_t stream_size_;
};
}; // namespace chrome_pdf
#endif // PDF_CHUNK_STREAM_H_
|