cocos2d / cocos2d-js__old__

cocos2d in JavaScript central repository
14 stars 9 forks source link

FileLoad #65

Open houguohua opened 11 years ago

houguohua commented 11 years ago

I need get the file pointer from the CCFileUtils. Because sometimes,I need only a small part info from a large file. If the CCFileUtils class provides this interface,It can save mush memory. eg, FILE* CCFileUtils::openFile(const char* path, const char* mode) // Open the bundle FILE* fp = CCFileUtils::openFile(path, "rb"); if (!fp) {
WARN_VARG("Failed to open file: '%s'.", path); return NULL; }

char identifier[] = { 'C', 'K', 'B', '\n' };

// Read header info
char sig[4];

if (fread(sig, 1, 4, fp) != 4 || memcmp(sig, identifier, 4) != 0)
{
    LOG_ERROR_VARG("Invalid bundle header: %s", path);
    fclose(fp);
    return NULL;
}
minggo commented 11 years ago

On Android, resources are stored in .apk file, which is zip file. Then you can not use fopen.

houguohua commented 11 years ago

On Android,we can write the file from .apk file into data/data directory.

minggo commented 11 years ago

If the resource is not in apk file, you can use fopen by yourself. You can use CCFileUtils::fullPathForFileName() to get full path of a file name, then you can pass the full path to fopen().