diff --git a/lib/bytes.cc b/lib/bytes.cc index 14f7b0eb..532dd1c9 100644 --- a/lib/bytes.cc +++ b/lib/bytes.cc @@ -258,6 +258,11 @@ void Bytes::writeToFile(const std::string& filename) const f.close(); } +void Bytes::writeTo(std::ostream& stream) const +{ + stream.write((const char*) cbegin(), size()); +} + ByteReader Bytes::reader() const { return ByteReader(*this); diff --git a/lib/bytes.h b/lib/bytes.h index 885dc0d1..6f8c2554 100644 --- a/lib/bytes.h +++ b/lib/bytes.h @@ -57,6 +57,7 @@ class Bytes ByteWriter writer(); void writeToFile(const std::string& filename) const; + void writeTo(std::ostream& stream) const; private: std::shared_ptr> _data; diff --git a/lib/imagewriter/imgimagewriter.cc b/lib/imagewriter/imgimagewriter.cc index 2542e3e6..d19b1308 100644 --- a/lib/imagewriter/imgimagewriter.cc +++ b/lib/imagewriter/imgimagewriter.cc @@ -46,7 +46,7 @@ class ImgImageWriter : public ImageWriter if (sector) { outputFile.seekp(sector->logicalTrack*trackSize + sector->logicalSide*headSize + sector->logicalSector*numBytes, std::ios::beg); - outputFile.write((const char*) sector->data.cbegin(), sector->data.size()); + sector->data.slice(0, numBytes).writeTo(outputFile); } } }