//----------------------------------------------------------------// int zipfs_get_stat ( char const* path, zipfs_stat* filestat ) { struct stat s; int result; ZIPFSVirtualPath* mount; char* abspath; filestat->mExists = 0; abspath = zipfs_get_abs_filepath ( path ); mount = find_best_virtual_path ( abspath ); if ( mount ) { const char* localpath = ZIPFSVirtualPath_GetLocalPath ( mount, abspath ); if ( abspath ) { ZIPFSZipFileEntry* entry; result = stat ( mount->mArchive->mFilename, &s ); if ( result ) return -1; filestat->mExists = 1; filestat->mIsDir = 1; filestat->mSize = 0; filestat->mTimeCreated = s.st_ctime; filestat->mTimeModified = s.st_mtime; filestat->mTimeViewed = s.st_atime; entry = ZIPFSZipFile_FindEntry ( mount->mArchive, localpath ); if ( entry ) { filestat->mIsDir = 0; filestat->mSize = entry->mUncompressedSize; } } } else { result = stat ( path, &s ); if ( result ) return -1; filestat->mExists = 1; filestat->mIsDir = S_ISDIR ( s.st_mode ); filestat->mSize = ( size_t )s.st_size; filestat->mTimeCreated = s.st_ctime; filestat->mTimeModified = s.st_mtime; filestat->mTimeViewed = s.st_atime; } return 0; }
//----------------------------------------------------------------// ZIPFSZipStream* ZIPFSZipStream_Open ( ZIPFSZipFile* archive, const char* entryname ) { int result; FILE* file = 0; ZIPFSZipStream* self = 0; ZIPFSZipFileEntry* entry; FileHeader fileHeader; entry = ZIPFSZipFile_FindEntry ( archive, entryname ); if ( !entry ) goto error; file = fopen ( archive->mFilename, "rb" ); if ( !file ) goto error; self = ( ZIPFSZipStream* )calloc ( 1, sizeof ( ZIPFSZipStream )); self->mFile = file; self->mEntry = entry; // finfo->entry = (( entry->symlink != NULL ) ? entry->symlink : entry ); // seek to the base of the zip file header result = fseek ( file, entry->mFileHeaderAddr, SEEK_SET ); if ( result ) goto error; // read local header result = read_file_header ( file, &fileHeader ); if ( result ) goto error; // sanity check if ( fileHeader.mCrc32 != entry->mCrc32 ) goto error; // skip the extra field, etc. result = fseek ( file, fileHeader.mNameLength + fileHeader.mExtraFieldLength, SEEK_CUR ); if ( result ) goto error; // this is the base address of the compressed file data self->mBaseAddr = ftell ( file ); // looks like all systems are go, so time to set up the buffers (or not) result = ( entry->mUncompressedSize <= ZIP_STREAM_BUFFER_MAX ) ? ZIPFSZipStream_FullyCache ( self ) : ZIPFSZipStream_InitBuffers ( self ); if ( result ) goto error; return self; error: if ( self ) { ZIPFSZipStream_Close ( self ); } return 0; }