27#if defined HAVE_CONFIG_H
33#include "id3/io_decorators.h"
38void io::WindowedReader::setWindow(pos_type beg, size_type size)
40 ID3D_NOTICE(
"WindowedReader::setWindow() [beg, size] = [" <<
41 this->getBeg() <<
", " << size <<
"]" );
42 pos_type cur = this->getCur();
45 this->setEnd(_reader.getEnd());
53 ID3D_NOTICE(
"WindowedReader::setWindow(): after setCur(beg), cur = "<<
56 this->skipChars(size);
57 ID3D_NOTICE(
"WindowedReader::setWindow(): after skipChars, cur = " <<
60 this->setEnd(this->getCur());
62 ID3D_NOTICE(
"WindowedReader::setWindow() [beg, cur, end] = [" << this->getBeg() <<
", " << this->getCur() <<
", " << this->getEnd() <<
"]" );
73 if (beg <= this->getEnd() && beg >= _reader.getBeg())
77 else if (beg > this->getEnd())
79 ID3D_WARNING(
"WindowedReader::setBeg() failed, [beg, _end] = " <<
80 beg <<
", " << this->getEnd() <<
"]" );
84 ID3D_WARNING(
"WindowedReader::setBeg() failed, [beg, _beg] = " <<
85 beg <<
", " << this->getBeg() <<
"]" );
94 if (this->getBeg() <= end && end <= _reader.getEnd())
100 ID3D_WARNING(
"WindowedReader::setEnd() failed, end = " << end );
101 ID3D_WARNING(
"WindowedReader::setEnd() failed, beg = " <<
103 ID3D_WARNING(
"WindowedReader::setEnd() failed, super.end = " <<
112 int_type ch = END_OF_READER;
113 if (this->inWindow())
115 ch = _reader.readChar();
119 ID3D_WARNING(
"io::WindowedReader::readChar: not in window, " <<
120 "pos = " << this->getCur() <<
", window = [" <<
121 this->getBeg() <<
", " << this->getEnd() <<
"]");
128 int_type ch = END_OF_READER;
129 if (this->inWindow())
131 ch = _reader.peekChar();
138 pos_type cur = this->getCur();
140 if (this->inWindow(cur))
149 size_type numChars = 0;
150 ID3D_NOTICE(
"CharReader::readChars(): len = " << len );
151 for (; numChars < len; ++numChars)
157 char_type ch = this->readChar();
163 ID3D_NOTICE(
"CharReader::readChars(): numChars = " << len );
171 return END_OF_READER;
173 char_type ch = _reader.readChar();
174 if (ch == 0x0D && this->peekChar() == 0x0A)
176 ID3D_NOTICE(
"LineFeedReader::readChar(): found CRLF at pos " <<
178 ch = _reader.readChar();
187 return END_OF_READER;
189 char_type ch = _reader.readChar();
190 if (ch == 0xFF && this->peekChar() == 0x00)
192 ID3D_NOTICE(
"UnsyncedReader::readChar(): found sync at pos " <<
199io::CompressedReader::CompressedReader(
ID3_Reader& reader, size_type newSize)
200 : _uncompressed(new char_type[newSize])
204 BString binary = readBinary(reader, oldSize);
206 ::uncompress(_uncompressed,
207 reinterpret_cast<luint*
>(&newSize),
208 reinterpret_cast<const uchar*
>(binary.data()),
210 this->setBuffer(_uncompressed, newSize);
213io::CompressedReader::~CompressedReader()
215 delete [] _uncompressed;
220 if (_last == 0xFF && (ch == 0x00 || ch >= 0xE0))
222 _writer.writeChar(
'\0');
225 _last = _writer.writeChar(ch);
229void io::UnsyncedWriter::flush()
233 _last = _writer.writeChar(
'\0');
240io::UnsyncedWriter::writeChars(
const char_type buf[], size_type len)
242 pos_type beg = this->getCur();
243 ID3D_NOTICE(
"UnsyncedWriter::writeChars(): len = " << len );
244 for (
size_t i = 0; i < len; ++i)
250 this->writeChar(buf[i]);
252 size_type numChars = this->getCur() - beg;
253 ID3D_NOTICE(
"CharWriter::writeChars(): numChars = " << numChars );
257void io::CompressedWriter::flush()
259 if (_data.size() == 0)
263 const char_type* data =
reinterpret_cast<const char_type*
>(_data.data());
264 size_type dataSize = _data.size();
265 _origSize = dataSize;
269 unsigned long newDataSize = dataSize + (dataSize / 10) + 12;
270 char_type* newData =
new char_type[newDataSize];
271 if (::compress(newData, &newDataSize, data, dataSize) != Z_OK)
274 ID3D_WARNING(
"io::CompressedWriter: error compressing");
275 _writer.writeChars(data, dataSize);
277 else if (newDataSize < dataSize)
279 ID3D_NOTICE(
"io::CompressedWriter: compressed size = " << newDataSize <<
", original size = " << dataSize );
280 _writer.writeChars(newData, newDataSize);
284 ID3D_NOTICE(
"io::CompressedWriter: no compression!compressed size = " << newDataSize <<
", original size = " << dataSize );
285 _writer.writeChars(data, dataSize);
292io::CompressedWriter::writeChars(
const char_type buf[], size_type len)
294 ID3D_NOTICE(
"io::CompressedWriter: writing chars: " << len );
295 _data.append(buf, len);
virtual size_type remainingBytes()
const T & min(const T &a, const T &b)