0

I'm currently using NDK AssetManager_open and AAsset_read to read files in asset folder.

    // open a file and read its content 
    AAsset* asset AAssetManager_open(engine.app->activity->assetManager, name.c_str(), AASSET_MODE_UNKNOWN);
    if (NULL == asset) {
        LOGE("_ASSET_NOT_FOUND_: %s", name.c_str());
        return nullptr;
    }

    long size = AAsset_getLength(asset);
    void* buffer = malloc(size);

    AAsset_read(asset, buffer, size);
    AAsset_close(asset);

NDK AAsset offers these functions :

   int AAsset_read(AAsset* asset, void* buf, size_t count);
   off_t AAsset_seek(AAsset* asset, off_t offset, int whence);
   void AAsset_close(AAsset* asset);
   const void* AAsset_getBuffer(AAsset* asset);
   off_t AAsset_getLength(AAsset* asset);
   off_t AAsset_getRemainingLength(AAsset* asset);

I'm looking for a way to construct an std::istream for an AAsset*.
I don't want to read all of the file contents and then create the istream.

Any idea on how to construct an istream working on an AAsset*?

amin
  • 3,672
  • 5
  • 33
  • 61
  • @Deduplicator no it is not – amin Mar 07 '15 at 07:32
  • You might want to elaborate by clarifying your question: [“This question may already have an answer here” - but it does not](http://meta.stackoverflow.com/questions/252252/this-question-may-already-have-an-answer-here-but-it-does-not). – Deduplicator Mar 07 '15 at 09:09
  • @Deduplicator I think amin is right. The other question asks for an ifstream, which will not work. amin asks for how to implement a class based on istream and that will work. I posted the answer in the other question, but it should the right answer here IMHO. – Tobias Wollgam Jul 16 '17 at 20:57

0 Answers0