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.");
107 m_fileInfo->setPath(path);
108 m_fileInfo->open(
true);
109 m_fileInfo->parseContainerFormat(diag);
112 m_stream = [
this]() -> std::istream & {
return this->m_fileInfo->stream(); };
130 ss <<
"ID: " <<
id();
131 if (!
name().empty()) {
132 ss <<
", name: \"" <<
name() <<
"\"";
135 ss <<
", mime-type: \"" <<
mimeType() <<
"\"";
145 m_description.clear();
168 auto file = make_unique<FileDataBlock>(path, diag);
169 const auto fileName = file->fileInfo()->fileName();
170 if (!fileName.empty()) {
173 const char *
mimeType = file->fileInfo()->mimeType();
178 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.
virtual ~StreamDataBlock()
Discards buffered data.
Contains all classes and functions of the TagInfo library.
const std::string & mimeType() const
Returns the MIME-type of the attachment.
std::string label() const
Returns a label for the track.
The Diagnostics class is a container for DiagMessage.
std::istream::pos_type m_startOffset