mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-02 03:20:06 +00:00
Added a method MemoryBlock::replaceWith(). Changed FileInputStream to avoid cacheing the length of the file.
This commit is contained in:
parent
e89983a1ab
commit
0194486115
7 changed files with 26 additions and 12 deletions
|
|
@ -30,7 +30,6 @@ FileInputStream::FileInputStream (const File& f)
|
|||
: file (f),
|
||||
fileHandle (nullptr),
|
||||
currentPosition (0),
|
||||
totalSize (0),
|
||||
status (Result::ok()),
|
||||
needToSeek (true)
|
||||
{
|
||||
|
|
@ -45,7 +44,7 @@ FileInputStream::~FileInputStream()
|
|||
//==============================================================================
|
||||
int64 FileInputStream::getTotalLength()
|
||||
{
|
||||
return totalSize;
|
||||
return file.getSize();
|
||||
}
|
||||
|
||||
int FileInputStream::read (void* buffer, int bytesToRead)
|
||||
|
|
@ -69,7 +68,7 @@ int FileInputStream::read (void* buffer, int bytesToRead)
|
|||
|
||||
bool FileInputStream::isExhausted()
|
||||
{
|
||||
return currentPosition >= totalSize;
|
||||
return currentPosition >= getTotalLength();
|
||||
}
|
||||
|
||||
int64 FileInputStream::getPosition()
|
||||
|
|
@ -80,10 +79,14 @@ int64 FileInputStream::getPosition()
|
|||
bool FileInputStream::setPosition (int64 pos)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ private:
|
|||
//==============================================================================
|
||||
File file;
|
||||
void* fileHandle;
|
||||
int64 currentPosition, totalSize;
|
||||
int64 currentPosition;
|
||||
Result status;
|
||||
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)
|
||||
{
|
||||
if (numBytes > 0)
|
||||
|
|
|
|||
|
|
@ -150,6 +150,11 @@ public:
|
|||
*/
|
||||
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.
|
||||
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
|
||||
|
|
|
|||
|
|
@ -413,8 +413,6 @@ int64 juce_fileSetPosition (void* handle, int64 pos)
|
|||
|
||||
void FileInputStream::openHandle()
|
||||
{
|
||||
totalSize = file.getSize();
|
||||
|
||||
const int f = open (file.getFullPathName().toUTF8(), O_RDONLY, 00644);
|
||||
|
||||
if (f != -1)
|
||||
|
|
|
|||
|
|
@ -222,8 +222,6 @@ int64 juce_fileSetPosition (void* handle, int64 pos)
|
|||
|
||||
void FileInputStream::openHandle()
|
||||
{
|
||||
totalSize = file.getSize();
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ int OutputStream::writeFromInputStream (InputStream& source, int64 numBytesToWri
|
|||
|
||||
int numWritten = 0;
|
||||
|
||||
while (numBytesToWrite > 0 && ! source.isExhausted())
|
||||
while (numBytesToWrite > 0)
|
||||
{
|
||||
char buffer [8192];
|
||||
const int num = source.read (buffer, (int) jmin (numBytesToWrite, (int64) sizeof (buffer)));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue