- explicit ChecksumOutputStream(OutputStream &o);
- virtual ~ChecksumOutputStream() { }
-
- /* Once a checksum is computed, no further data should be written to the
- * stream. */
- const uint8_t *finish_and_checksum();
- size_t checksum_size() const { return csum.checksum_size(); }
-
-protected:
- virtual void write_internal(const void *data, size_t len);
-
-private:
- OutputStream ℜ
- SHA1Checksum csum;
-};
-
-/* Simple wrappers that encode integers using a StringOutputStream and return
- * the encoded result. */
-std::string encode_u16(uint16_t val);
-std::string encode_u32(uint32_t val);
-std::string encode_u64(uint64_t val);
-
-struct uuid {
- uint8_t bytes[16];
-};
-
-/* A class which is used to pack multiple objects into a single segment, with a
- * lookup table to quickly locate each object. Call new_object() to get an
- * OutputStream to which a new object may be written, and optionally
- * finish_object() when finished writing the current object. Only one object
- * may be written to a segment at a time; if multiple objects must be written
- * concurrently, they must be to different segments. */
-class SegmentWriter {
-public:
- SegmentWriter(OutputStream *output, struct uuid u);
- ~SegmentWriter();
-
- struct uuid get_uuid() const { return id; }
-
- // Start writing out a new object to this segment.
- OutputStream *new_object();
- void finish_object();
-
- // Determine size of segment data written out so far.
- size_t get_size() const { return raw_out->get_pos(); }
-
- // Utility functions for generating and formatting UUIDs for display.
- static struct uuid generate_uuid();
- static std::string format_uuid(const struct uuid u);
+ // New segments will be stored in the given directory.
+ TarSegmentStore(RemoteStore *remote,
+ LocalDb *db = NULL)
+ { this->remote = remote; this->db = db; }
+ ~TarSegmentStore() { sync(); }
+
+ // Writes an object to segment in the store, and returns the name
+ // (segment/object) to refer to it. The optional parameter group can be
+ // used to control object placement; objects with different group
+ // parameters are kept in separate segments.
+ ObjectReference write_object(const char *data, size_t len,
+ const std::string &group = "",
+ const std::string &checksum = "",
+ double age = 0.0);
+
+ // Ensure all segments have been fully written.
+ void sync();
+
+ // Dump statistics to stdout about how much data has been written
+ void dump_stats();