Browse Source

Added an overloaded read method to InputStream which takes a size_t as the size parameter, rather than an int

tags/2021-05-28
jules 6 years ago
parent
commit
f746672c19
3 changed files with 25 additions and 3 deletions
  1. +3
    -3
      modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp
  2. +20
    -0
      modules/juce_core/streams/juce_InputStream.cpp
  3. +2
    -0
      modules/juce_core/streams/juce_InputStream.h

+ 3
- 3
modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp View File

@@ -30,11 +30,11 @@ namespace juce
namespace WindowsMediaCodec
{
class JuceIStream : public ComBaseClassHelper <IStream>
class JuceIStream : public ComBaseClassHelper<IStream>
{
public:
JuceIStream (InputStream& in) noexcept
: ComBaseClassHelper <IStream> (0), source (in)
: ComBaseClassHelper<IStream> (0), source (in)
{
}
@@ -48,7 +48,7 @@ public:
JUCE_COMRESULT Read (void* dest, ULONG numBytes, ULONG* bytesRead)
{
auto numRead = source.read (dest, numBytes);
auto numRead = source.read (dest, (size_t) numBytes);
if (bytesRead != nullptr)
*bytesRead = numRead;


+ 20
- 0
modules/juce_core/streams/juce_InputStream.cpp View File

@@ -33,6 +33,26 @@ int64 InputStream::getNumBytesRemaining()
return len;
}
ssize_t InputStream::read (void* destBuffer, size_t size)
{
ssize_t totalRead = 0;
while (size > 0)
{
auto numToRead = (int) std::min (size, (size_t) 0x70000000);
auto numRead = read (juce::addBytesToPointer (destBuffer, totalRead), numToRead);
jassert (numRead <= numToRead);
if (numRead < 0) return (ssize_t) numRead;
if (numRead == 0) break;
size -= (size_t) numRead;
totalRead += numRead;
}
return totalRead;
}
char InputStream::readByte()
{
char temp = 0;


+ 2
- 0
modules/juce_core/streams/juce_InputStream.h View File

@@ -77,6 +77,8 @@ public:
*/
virtual int read (void* destBuffer, int maxBytesToRead) = 0;
ssize_t read (void* destBuffer, size_t maxBytesToRead);
/** Reads a byte from the stream.
If the stream is exhausted, this will return zero.
@see OutputStream::writeByte


Loading…
Cancel
Save