uint64 ZipStream::size() const { ZZIP_STAT zs; int ret = zzip_file_stat(handle, &zs); assert( ret != -1 ); return zs.st_size; }
long ZipSource::GetSize() const { ZZIP_STAT st; return zzip_file_stat(file, &st) >= 0 ? (long)st.st_size : -1l; }
/** => zzip_dir_stat * This function will obtain information about a opened file which may be * either real/zipped. The file is supposed to be open (otherwise -1 is * returned). The st_size stat-member contains the uncompressed size. * The optional d_name is never set here. For a real file, we do set the * d_csize := st_size and d_compr := 0 for meaningful defaults. */ int zzip_fstat (ZZIP_FILE* file, ZZIP_STAT* zs) { if (ZZIP_file_real(file)) { struct stat st; if (fstat (file->fd, &st) < 0) return -1; zs->st_size = st.st_size; zs->d_csize = st.st_size; zs->d_compr = 0; return 0; }else{ return zzip_file_stat (file, zs); } }
/** => zzip_dir_stat * This function will obtain information about a opened file which may be * either real/zipped. The file is supposed to be open (otherwise -1 is * returned). The st_size stat-member contains the uncompressed size. * The optional d_name is never set here. For a real file, we do set the * d_csize := st_size and d_compr := 0 for meaningful defaults. */ int zzip_fstat (ZZIP_FILE* file, ZZIP_STAT* zs) { if (ZZIP_file_real(file)) { // JMW TODO! #if (WINDOWSPC>0) struct stat st; if (fstat (file->fd, &st) < 0) return -1; zs->st_size = st.st_size; zs->d_csize = st.st_size; zs->d_compr = 0; return 0; #else return 0; #endif }else{ return zzip_file_stat (file, zs); } }
/** Creates a buffer of all the data in the SRTM file. The uncompressed version is used if available. * * \returns The length of the side of the data (e.g. 1201 or 3601) * \note The buffer returned is owned by the caller of this function and _must_ be freed after usage. */ int SrtmZipFile::getData(QString filename, qint16 **buffer) { *buffer = 0; QFileInfo fi(filename); QString uncompressedFile = fi.path()+'/'+fi.completeBaseName(); int size = 0; if (QFileInfo(uncompressedFile).exists()) { QFile file(uncompressedFile); if (!file.open(QIODevice::ReadOnly)) { qCritical() << "ZIP(Uncompressed): Could not open file" << uncompressedFile << file.errorString(); return 0; } size = sqrt(file.size()/2); if (size*size*2 != file.size()) { qCritical() << "ZIP(Uncompressed): Invalid data: Not a square!"; } *buffer = new qint16[file.size()/2]; if (!*buffer) { qCritical() << "ZIP(Uncompressed): Could not allocate buffer."; return 0; } if (file.read((char *)*buffer, file.size()) != file.size()) { qCritical() << "ZIP(Uncompressed): Could not read all bytes."; } file.close(); } else { ZZIP_DIR* dir = zzip_dir_open(filename.toAscii(), 0); if (!dir) { qCritical() << "ZIP: Could not open zip file" << filename; return 0; } ZZIP_FILE* fp = zzip_file_open(dir, fi.completeBaseName().toAscii(), 0); if (!fp) { qCritical() << "ZIP: Could not find" << fi.completeBaseName() << "in" << filename; return 0; } ZZIP_STAT stat; if (zzip_file_stat(fp, &stat) == -1) { qCritical() << "ZIP: Could not get info about" << uncompressedFile; return 0; } size = sqrt(stat.st_size/2); if (size*size*2 != stat.st_size) { qCritical() << "ZIP: Invalid data: Not a square!"; } *buffer = new qint16[stat.st_size/2]; if (zzip_file_read(fp, *buffer, stat.st_size) != stat.st_size) { qCritical() << "ZIP: Could not read all bytes."; delete *buffer; *buffer = 0; return 0; } //store uncompressed content on disk? if (false) { QFile file(uncompressedFile); if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { qCritical() << "ZIP(Writing): Could not open file" << uncompressedFile << file.errorString(); } else { file.write((char *)*buffer, stat.st_size); file.close(); } } zzip_file_close(fp); zzip_dir_close(dir); } return size; }