#include "cfstream.h" #include "cfexception.h" #include "idirectoryentry.h" #include "compoundfile.h" using namespace CFCPP; CFStream::CFStream(CompoundFile* compFile, std::weak_ptr dirEntry) : CFItem(compFile) { if (dirEntry.expired() || dirEntry.lock()->getSid() < 0) throw CFException("Attempting to create a CFStorage using an unitialized directory"); this->dirEntry = dirEntry; } void CFStream::SetData(const std::vector &data) { CheckDisposed(); compoundFile->FreeData(this); compoundFile->WriteData(shared_from_this(), data); } void CFStream::Write(const std::vector &data, std::streamsize position) { Write(data, position, 0, data.size()); } void CFStream::Write(const std::vector &data, std::streamsize position, int offset, int count) { CheckDisposed(); compoundFile->WriteData(shared_from_this(), data, position, offset, count); } void CFStream::Append(const std::vector &data) { CheckDisposed(); if (size() > 0) { compoundFile->AppendData(shared_from_this(), data); } else { compoundFile->WriteData(shared_from_this(), data); } } std::vector CFStream::getData() const { CheckDisposed(); return compoundFile->GetData(this); } int CFStream::Read(std::vector &buffer, std::streamsize position, int count) { CheckDisposed(); return compoundFile->ReadData(this, position, buffer, 0, count); } int CFStream::Read(std::vector &buffer, std::streamsize position, int offset, int count) { CheckDisposed(); return compoundFile->ReadData(this, position, buffer, offset, count); } void CFStream::CopyFrom(const Stream &input) { CheckDisposed(); std::vector buffer(Length(input)); // if (input.CanSeek) { input->seek(0, std::ios::beg); } input->read(reinterpret_cast(buffer.data()), Length(input)); SetData(buffer); } void CFStream::Resize(std::streamsize length) { compoundFile->SetStreamLength(shared_from_this(), length); }