| @@ -30,7 +30,6 @@ FileInputStream::FileInputStream (const File& f) | |||||
| : file (f), | : file (f), | ||||
| fileHandle (nullptr), | fileHandle (nullptr), | ||||
| currentPosition (0), | currentPosition (0), | ||||
| totalSize (0), | |||||
| status (Result::ok()), | status (Result::ok()), | ||||
| needToSeek (true) | needToSeek (true) | ||||
| { | { | ||||
| @@ -45,7 +44,7 @@ FileInputStream::~FileInputStream() | |||||
| //============================================================================== | //============================================================================== | ||||
| int64 FileInputStream::getTotalLength() | int64 FileInputStream::getTotalLength() | ||||
| { | { | ||||
| return totalSize; | |||||
| return file.getSize(); | |||||
| } | } | ||||
| int FileInputStream::read (void* buffer, int bytesToRead) | int FileInputStream::read (void* buffer, int bytesToRead) | ||||
| @@ -69,7 +68,7 @@ int FileInputStream::read (void* buffer, int bytesToRead) | |||||
| bool FileInputStream::isExhausted() | bool FileInputStream::isExhausted() | ||||
| { | { | ||||
| return currentPosition >= totalSize; | |||||
| return currentPosition >= getTotalLength(); | |||||
| } | } | ||||
| int64 FileInputStream::getPosition() | int64 FileInputStream::getPosition() | ||||
| @@ -80,10 +79,14 @@ int64 FileInputStream::getPosition() | |||||
| bool FileInputStream::setPosition (int64 pos) | bool FileInputStream::setPosition (int64 pos) | ||||
| { | { | ||||
| jassert (openedOk()); | jassert (openedOk()); | ||||
| pos = jlimit ((int64) 0, totalSize, pos); | |||||
| needToSeek |= (currentPosition != pos); | |||||
| currentPosition = pos; | |||||
| if (pos != currentPosition) | |||||
| { | |||||
| pos = jlimit ((int64) 0, getTotalLength(), pos); | |||||
| needToSeek |= (currentPosition != pos); | |||||
| currentPosition = pos; | |||||
| } | |||||
| return true; | return true; | ||||
| } | } | ||||
| @@ -82,7 +82,7 @@ private: | |||||
| //============================================================================== | //============================================================================== | ||||
| File file; | File file; | ||||
| void* fileHandle; | void* fileHandle; | ||||
| int64 currentPosition, totalSize; | |||||
| int64 currentPosition; | |||||
| Result status; | Result status; | ||||
| bool needToSeek; | bool needToSeek; | ||||
| @@ -175,6 +175,16 @@ void MemoryBlock::append (const void* const srcData, const size_t numBytes) | |||||
| } | } | ||||
| } | } | ||||
| void MemoryBlock::replaceWith (const void* const srcData, const size_t numBytes) | |||||
| { | |||||
| if (numBytes > 0) | |||||
| { | |||||
| jassert (srcData != nullptr); // this must not be null! | |||||
| setSize (numBytes); | |||||
| memcpy (data, srcData, numBytes); | |||||
| } | |||||
| } | |||||
| void MemoryBlock::insert (const void* const srcData, const size_t numBytes, size_t insertPosition) | void MemoryBlock::insert (const void* const srcData, const size_t numBytes, size_t insertPosition) | ||||
| { | { | ||||
| if (numBytes > 0) | if (numBytes > 0) | ||||
| @@ -150,6 +150,11 @@ public: | |||||
| */ | */ | ||||
| void append (const void* data, size_t numBytes); | void append (const void* data, size_t numBytes); | ||||
| /** Resizes this block to the given size and fills its contents from the supplied buffer. | |||||
| The data pointer must not be null. | |||||
| */ | |||||
| void replaceWith (const void* data, size_t numBytes); | |||||
| /** Inserts some data into the block. | /** Inserts some data into the block. | ||||
| The dataToInsert pointer must not be null. This block's size will be increased accordingly. | The dataToInsert pointer must not be null. This block's size will be increased accordingly. | ||||
| If the insert position lies outside the valid range of the block, it will be clipped to | If the insert position lies outside the valid range of the block, it will be clipped to | ||||
| @@ -413,8 +413,6 @@ int64 juce_fileSetPosition (void* handle, int64 pos) | |||||
| void FileInputStream::openHandle() | void FileInputStream::openHandle() | ||||
| { | { | ||||
| totalSize = file.getSize(); | |||||
| const int f = open (file.getFullPathName().toUTF8(), O_RDONLY, 00644); | const int f = open (file.getFullPathName().toUTF8(), O_RDONLY, 00644); | ||||
| if (f != -1) | if (f != -1) | ||||
| @@ -222,8 +222,6 @@ int64 juce_fileSetPosition (void* handle, int64 pos) | |||||
| void FileInputStream::openHandle() | void FileInputStream::openHandle() | ||||
| { | { | ||||
| totalSize = file.getSize(); | |||||
| HANDLE h = CreateFile (file.getFullPathName().toWideCharPointer(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, | HANDLE h = CreateFile (file.getFullPathName().toWideCharPointer(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, | ||||
| OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0); | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0); | ||||
| @@ -241,7 +241,7 @@ int OutputStream::writeFromInputStream (InputStream& source, int64 numBytesToWri | |||||
| int numWritten = 0; | int numWritten = 0; | ||||
| while (numBytesToWrite > 0 && ! source.isExhausted()) | |||||
| while (numBytesToWrite > 0) | |||||
| { | { | ||||
| char buffer [8192]; | char buffer [8192]; | ||||
| const int num = source.read (buffer, (int) jmin (numBytesToWrite, (int64) sizeof (buffer))); | const int num = source.read (buffer, (int) jmin (numBytesToWrite, (int64) sizeof (buffer))); | ||||