summaryrefslogtreecommitdiff
path: root/xfa_test/pdf/chunk_stream.h
diff options
context:
space:
mode:
authorBo Xu <bo_xu@foxitsoftware.com>2014-10-28 23:03:33 -0700
committerBo Xu <bo_xu@foxitsoftware.com>2014-11-03 11:10:11 -0800
commitfdc00a7042d912aafaabddae4d9c84199921ef23 (patch)
tree32ab8ac91cc68d2cd15b9168782a71b3f3f5e7b9 /xfa_test/pdf/chunk_stream.h
parente9b38fa38de2c95d8260be31c57d9272c4d127ed (diff)
downloadpdfium-fdc00a7042d912aafaabddae4d9c84199921ef23.tar.xz
Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
Diffstat (limited to 'xfa_test/pdf/chunk_stream.h')
-rw-r--r--xfa_test/pdf/chunk_stream.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/xfa_test/pdf/chunk_stream.h b/xfa_test/pdf/chunk_stream.h
new file mode 100644
index 0000000000..fac1ec644d
--- /dev/null
+++ b/xfa_test/pdf/chunk_stream.h
@@ -0,0 +1,48 @@
+// 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 <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();
+
+ 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;
+
+ size_t GetLastByteBefore(size_t offset) const;
+ size_t GetFirstByteAfter(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_;
+};
+
+}; // namespace chrome_pdf
+
+#endif