6 #include <c++utilities/io/catchiofailure.h> 7 #include <c++utilities/io/copy.h> 27 StreamDataBlock::StreamDataBlock()
45 std::istream::off_type endOffset, std::ios_base::seekdir endDir)
49 auto currentPos = s.tellg();
56 IoUtilities::throwIoFailure(
"End offset is less than start offset.");
100 m_fileInfo->setPath(path);
101 m_fileInfo->open(
true);
102 m_fileInfo->parseContainerFormat(diag);
105 m_stream = [
this]() -> std::istream & {
return this->m_fileInfo->stream(); };
119 ss <<
"ID: " <<
id();
120 if (!
name().empty()) {
121 ss <<
", name: \"" <<
name() <<
"\"";
124 ss <<
", mime-type: \"" <<
mimeType() <<
"\"";
134 m_description.clear();
157 auto file = make_unique<FileDataBlock>(path, diag);
158 const auto fileName = file->fileInfo()->fileName();
159 if (!fileName.empty()) {
162 const char *
mimeType = file->fileInfo()->mimeType();
167 m_isDataFromFile =
true;
FileDataBlock(const std::string &path, Diagnostics &diag)
Constructs a new FileDataBlock with the specified path.
const std::unique_ptr< char[]> & buffer() const
Returns the data buffered via makeBuffer().
void setFile(const std::string &path, Diagnostics &diag)
Sets the data, name and MIME-type for the specified path.
std::unique_ptr< char[]> m_buffer
void makeBuffer() const
Buffers the data block.
uint64 id() const
Returns the ID of the attachment.
Contains utility classes helping to read and write streams.
const std::string & name() const
Returns the (file) name of the attachment.
void clear()
Resets the object to its initial state.
std::istream::pos_type endOffset() const
Returns the absolute end offset of the data block in the stream.
std::istream::pos_type m_endOffset
StreamDataBlock()
Constructs a new StreamDataBlock.
std::function< std::istream &()> m_stream
std::istream::pos_type startOffset() const
Returns the absolute start offset of the data block in the stream.
std::istream::pos_type size() const
Returns the size of the data block.
std::istream & stream() const
Returns the associated stream.
void copyTo(std::ostream &stream) const
Copies the data to the specified stream.
const std::string & mimeType() const
Returns the MIME-type of the attachment.
std::string label() const
Returns a label for the track.
std::istream::pos_type m_startOffset