Can I create an `juce::AudioFormatReader` from a buffer instead of a `juce::File`?

I’m trying to modify some code that reads a .wav file from a file and then creates a juce::SamplerSound from this file.

On Android it’s not possible to directly read files from the APK, but it’s possible to get their buffer. Since it’s sample files, they are small enough to load entirely on a buffer.

Is there a way to create a std::unique_ptr<juce::AudioFormatReader> reader from a buffer instead of a file?

I know that I could write to a file and then pass this file to mFormatManager.createReaderFor(file) but this would be inneficient

void HelloSamplerAudioProcessor::loadBuffer (const juce::String& path, uint8_t* buffer, size_t size)
    //no juce::File file anymore, I must find another way to create the reader below
    std::unique_ptr<juce::AudioFormatReader> reader{ mFormatManager.createReaderFor(file) };
    if (reader)
        juce::BigInteger range;
        range.setRange(0, 128, true);
        sampler.addSound(new juce::SamplerSound("Sample", *reader, range, 60, 0.1, 0.1, 10.0));
    } else {
        ALOGE(TAG, "reader error!");

there is a version that takes an InputStrean.
Use a MemoryInputStream to create one from your buffer.

Below is an excerpt from the SamplerPluginDemo demo.

inline std::unique_ptr<AudioFormatReader> makeAudioFormatReader (AudioFormatManager& manager,
                                                                 const void* sampleData,
                                                                 size_t dataSize)
    return std::unique_ptr<AudioFormatReader> (manager.createReaderFor (std::make_unique<MemoryInputStream> (sampleData, dataSize, false)));

You can find this (plugin example) here -