当前位置: 首页>>代码示例>>C++>>正文


C++ zip_fread函数代码示例

本文整理汇总了C++中zip_fread函数的典型用法代码示例。如果您正苦于以下问题:C++ zip_fread函数的具体用法?C++ zip_fread怎么用?C++ zip_fread使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了zip_fread函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ipsw_extract_to_memory

int ipsw_extract_to_memory(const char* ipsw, const char* infile, unsigned char** pbuffer, unsigned int* psize) {
	ipsw_archive* archive = ipsw_open(ipsw);
	if (archive == NULL || archive->zip == NULL) {
		error("ERROR: Invalid archive\n");
		return -1;
	}

	int zindex = zip_name_locate(archive->zip, infile, 0);
	if (zindex < 0) {
		error("ERROR: zip_name_locate: %s\n", infile);
		return -1;
	}

	struct zip_stat zstat;
	zip_stat_init(&zstat);
	if (zip_stat_index(archive->zip, zindex, 0, &zstat) != 0) {
		error("ERROR: zip_stat_index: %s\n", infile);
		return -1;
	}

	struct zip_file* zfile = zip_fopen_index(archive->zip, zindex, 0);
	if (zfile == NULL) {
		error("ERROR: zip_fopen_index: %s\n", infile);
		return -1;
	}

	int size = zstat.size;
	unsigned char* buffer = (unsigned char*) malloc(size+1);
	if (buffer == NULL) {
		error("ERROR: Out of memory\n");
		zip_fclose(zfile);
		return -1;
	}

	if (zip_fread(zfile, buffer, size) != size) {
		error("ERROR: zip_fread: %s\n", infile);
		zip_fclose(zfile);
		free(buffer);
		return -1;
	}

	buffer[size] = '\0';

	zip_fclose(zfile);
	ipsw_close(archive);

	*pbuffer = buffer;
	*psize = size;
	return 0;
}
开发者ID:Blackmamba0,项目名称:idevicerestore,代码行数:50,代码来源:ipsw.c

示例2: zip_read

static void zip_read(struct zip_file *file, const char *filename)
{
	int size = 1024, n, read = 0;
	char *mem = malloc(size);

	while ((n = zip_fread(file, mem + read, size - read)) > 0) {
		read += n;
		size = read * 3 / 2;
		mem = realloc(mem, size);
	}
	mem[read] = 0;
	(void) parse_xml_buffer(filename, mem, read, &dive_table, NULL);
	free(mem);
}
开发者ID:abentley,项目名称:subsurface,代码行数:14,代码来源:file.c

示例3: loadZipFile

/**
 * Read the contents of the first file of the ZIP file and load
 * it into a ModPlugFile.
**/
static ModPlugFile* loadZipFile(const char *path)
{
	ModPlugFile *self_ = NULL;
	int err = 0;
	struct zip *zf = zip_open(path, 0, &err);

	if (!zf) return NULL;

	struct zip_stat sb;

	// FIXME: Assumes the first file is the mod-file
	if (zip_stat_index(zf, 0, 0, &sb)) {
		MPSP_EPRINTF("failed to stat ZIP member: %s\n", zip_strerror(zf));
		goto exit1;
	}

	// FIXME: Assumes the first file is the mod-file
	struct zip_file *file = zip_fopen_index(zf, 0, 0);

	if (!file) {
		MPSP_EPRINTF("failed to open ZIP member: %s\n", zip_strerror(zf));
		goto exit1;
	}

	void *data = malloc(sb.size);

	if (!data) {
		MPSP_EPRINTF("failed to allocate memory: %s\n", strerror(errno));
		goto exit2;
	}

	if (zip_fread(file, data, sb.size) != sb.size) {
		MPSP_EPRINTF("failed to read ZIP member: %s\n", zip_file_strerror(file));
		goto exit3;
	}

	self_ = ModPlug_Load(data, sb.size);

exit3:
	free(data);

exit2:
	(void) zip_fclose(file);

exit1:
	(void) zip_close(zf);

	return self_;
}
开发者ID:tommie,项目名称:modplug,代码行数:53,代码来源:common.c

示例4: RuntimeError

cv::Mat ZipByteReader::Read(size_t seqId, const std::string& path, bool grayscale)
{
    // Find index of the file in .zip file.
    auto r = m_seqIdToIndex.find(seqId);
    if (r == m_seqIdToIndex.end())
        RuntimeError("Could not find file %s in the zip file, sequence id = %lu", path.c_str(), (long)seqId);

    zip_uint64_t index = std::get<0>((*r).second);
    zip_uint64_t size = std::get<1>((*r).second);

    auto contents = m_workspace.pop_or_create([size]() { return vector<unsigned char>(size); });
    if (contents.size() < size)
        contents.resize(size);
    auto zipFile = m_zips.pop_or_create([this]() { return OpenZip(); });
    {
        std::unique_ptr<zip_file_t, void(*)(zip_file_t*)> file(
            zip_fopen_index(zipFile.get(), index, 0),
            [](zip_file_t* f)
            {
                assert(f != nullptr);
                int err = zip_fclose(f);
                assert(ZIP_ER_OK == err);
#ifdef NDEBUG
                UNUSED(err);
#endif
            });
        assert(nullptr != file);
        if (nullptr == file)
        {
            RuntimeError("Could not open file %s in the zip file, sequence id = %lu, zip library error: %s",
                         path.c_str(), (long)seqId, GetZipError(zip_error_code_zip(zip_get_error(zipFile.get()))).c_str());
        }
        assert(contents.size() >= size);
        zip_uint64_t bytesRead = zip_fread(file.get(), contents.data(), size);
        assert(bytesRead == size);
        if (bytesRead != size)
        {
            RuntimeError("Bytes read %lu != expected %lu while reading file %s",
                         (long)bytesRead, (long)size, path.c_str());
        }
    }
    m_zips.push(std::move(zipFile));

    cv::Mat img; 
    img = cv::imdecode(cv::Mat(1, (int)size, CV_8UC1, contents.data()), grayscale ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR);
    assert(nullptr != img.data);
    m_workspace.push(std::move(contents));
    return img;
}
开发者ID:1132520084,项目名称:CNTK,代码行数:49,代码来源:ZipByteReader.cpp

示例5: do_read

static int
do_read(struct zip *z, const char *name, int flags,
	enum when when_ex, int ze_ex, int se_ex)
{
    struct zip_file *zf;
    enum when when_got;
    int err, ze_got, se_got;
    char b[8192];
    zip_int64_t n;
    char expected[80];
    char got[80];

    when_got = WHEN_NEVER;
    ze_got = se_got = 0;
    
    if ((zf=zip_fopen(z, name, flags)) == NULL) {
	when_got = WHEN_OPEN;
	zip_error_get(z, &ze_got, &se_got);
    }
    else {
	while ((n=zip_fread(zf, b, sizeof(b))) > 0)
	    ;
	if (n < 0) {
	    when_got = WHEN_READ;
	    zip_file_error_get(zf, &ze_got, &se_got);
	}
	err = zip_fclose(zf);
	if (when_got == WHEN_NEVER && err != 0) {
	    when_got = WHEN_CLOSE;
	    ze_got = err;
	    se_got = 0;
	}
    }

    if (when_got != when_ex || ze_got != ze_ex || se_got != se_ex) {
	zip_error_to_str(expected, sizeof(expected), ze_ex, se_ex);
	zip_error_to_str(got, sizeof(got), ze_got, se_got);
	printf("%s: %s: got %s error (%s), expected %s error (%s)\n",
	       prg, name,
	       when_name[when_got], got, 
	       when_name[when_ex], expected);
	return 1;
    }
    else if (verbose)
	printf("%s: %s: passed\n", prg, name);

    return 0;
}
开发者ID:CLQ201010,项目名称:iTools,代码行数:48,代码来源:fread.c

示例6: ASSERT

const uint CCZipFile::read(void *dest, const uint size)
{
	ASSERT( m_File != NULL && m_apkArchive != NULL );

	// Regular file handle
	const uint sz = zip_fread( m_File, dest, size );
	ASSERT( sz == size );
	if( sz > 0 )
	{
		m_Position += size;
		return size;
	}
	ASSERT_MESSAGE( false, "File::Read(...) : ERROR! Error reading" );

    return 0;
}
开发者ID:Orange-OpenSource,项目名称:2c,代码行数:16,代码来源:CCDeviceFileManager.cpp

示例7: php_zip_ops_read

/* {{{ php_zip_ops_read */
static size_t php_zip_ops_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
{
	int n = 0;
	STREAM_DATA_FROM_STREAM();

	if (self->za && self->zf) {
		n = (size_t)zip_fread(self->zf, buf, (int)count);

		if (n == 0) {
			stream->eof = 1;
		} else {
			self->cursor += n;
		}
	}
	return n<1 ? 0 : n;
}
开发者ID:Skull-Li,项目名称:dezend,代码行数:17,代码来源:zip_stream.c

示例8: sr_sessionfile_check

/** @private */
SR_PRIV int sr_sessionfile_check(const char *filename)
{
    struct stat st;
    struct zip *archive;
    struct zip_file *zf;
    struct zip_stat zs;
    int version, ret;
    char s[11];

    if (!filename)
        return SR_ERR_ARG;

    if (stat(filename, &st) == -1) {
        sr_err("Couldn't stat %s: %s", filename, strerror(errno));
        return SR_ERR;
    }

    if (!(archive = zip_open(filename, 0, &ret)))
        /* No logging: this can be used just to check if it's
         * a sigrok session file or not. */
        return SR_ERR;

    /* check "version" */
    version = 0;
    if (!(zf = zip_fopen(archive, "version", 0))) {
        sr_dbg("Not a sigrok session file: no version found.");
        return SR_ERR;
    }
    if ((ret = zip_fread(zf, s, 10)) == -1)
        return SR_ERR;
    zip_fclose(zf);
    s[ret] = 0;
    version = strtoull(s, NULL, 10);
    if (version > 2) {
        sr_dbg("Cannot handle sigrok session file version %d.", version);
        return SR_ERR;
    }
    sr_spew("Detected sigrok session file version %d.", version);

    /* read "metadata" */
    if (zip_stat(archive, "metadata", 0, &zs) == -1) {
        sr_dbg("Not a valid sigrok session file.");
        return SR_ERR;
    }

    return SR_OK;
}
开发者ID:DoctorCannibal,项目名称:DSView,代码行数:48,代码来源:session_file.c

示例9: distance

void ZipFile::Work_ReadFile(uv_work_t* req) {
    closure_t *closure = static_cast<closure_t *>(req->data);

    struct zip_file *zf_ptr = NULL;

    int idx = -1;

    std::vector<std::string>::iterator it = std::find(closure->zf->names_.begin(),
                                                      closure->zf->names_.end(),
                                                      closure->name);
    if (it != closure->zf->names_.end()) {
        idx = distance(closure->zf->names_.begin(), it);
    }

    if (idx == -1) {
        std::stringstream s;
        s << "No file found by the name of: '" << closure->name << "\n";
        closure->error = true;
        closure->error_name = s.str();
    } else {
        if ((zf_ptr = zip_fopen_index(closure->za, idx, 0)) == NULL) {
            std::stringstream s;
            s << "cannot open file #" << idx << " in "
              << closure->name << ": archive error: " << zip_strerror(closure->za) << "\n";
            closure->error = true;
            closure->error_name = s.str();
        } else {
            struct zip_stat st;
            zip_stat_index(closure->za, idx, 0, &st);
            closure->data.clear();
            closure->data.resize(st.size);

            int result =  0;
            result = static_cast<int>(zip_fread(zf_ptr, reinterpret_cast<void*> (&closure->data[0]), closure->data.size()));

            if (result < 0) {
                std::stringstream s;
                s << "error reading file #" << idx << " in "
                  << closure->name << ": archive error: " << zip_file_strerror(zf_ptr) << "\n";
                closure->error = true;
                closure->error_name = s.str();
            }
        }
    }
    zip_fclose(zf_ptr);
}
开发者ID:anoopsinha,项目名称:maui-epub,代码行数:46,代码来源:node_zipfile.cpp

示例10: zip_fopen

uint8_t *ReadFromZip(zip *archive, const char* filename, size_t *size) {
	// Figure out the file size first.
	struct zip_stat zstat;
	zip_file *file = zip_fopen(archive, filename, ZIP_FL_NOCASE|ZIP_FL_UNCHANGED);
	if (!file) {
		ELOG("Error opening %s from ZIP", filename);
		return 0;
	}
	zip_stat(archive, filename, ZIP_FL_NOCASE|ZIP_FL_UNCHANGED, &zstat);

	uint8_t *contents = new uint8_t[zstat.size + 1];
	zip_fread(file, contents, zstat.size);
	zip_fclose(file);
	contents[zstat.size] = 0;

	*size = zstat.size;
	return contents;
}
开发者ID:Orphis,项目名称:ppsspp,代码行数:18,代码来源:zip_read.cpp

示例11: zip_fread

ByteStream::size_type ZipFileByteStream::ReadBytes(void *buf, size_type len)
{
    if (len == 0) return 0;

    if ( _file == nullptr )
        return 0;
    
    ssize_t numRead = zip_fread(_file, buf, len);
    if ( numRead < 0 )
    {
        Close();
        return 0;
    }

	_eof = (_file->bytes_left == 0);
    
    return numRead;
}
开发者ID:chrisDwarner,项目名称:readium-sdk,代码行数:18,代码来源:byte_stream.cpp

示例12: FileRead

extern size_t FileRead( void *handle, void *buffer, size_t length )
{
    data_source     *ds = handle;
    size_t          amt;

    switch( ds->type ) {
    case DS_FILE:
        amt = read( ds->fhandle, buffer, length );
        break;
    case DS_ZIP:
        amt = zip_fread( ds->zf, buffer, length );
        break;
    default:
        amt = 0;
    }

    return( amt );
}
开发者ID:ABratovic,项目名称:open-watcom-v2,代码行数:18,代码来源:setupio.c

示例13: _zip_fseek_by_reading

int _zip_fseek_by_reading(struct zip_file* zf, size_t toread)
{
    char bytes[1024];
    while (toread > 0) {
        ssize_t numRead = zip_fread(zf, bytes, (toread < 1024 ? toread : 1024));
        if (numRead < 0 )
            return -1;      /* error already set */
        if (numRead == 0) {
            /* avoid infinite loops */
            _zip_error_set(&zf->error, ZIP_ER_INCONS, 0);
            return -1;
        }
        
        toread -= numRead;
    }
    
    /* zf has been updated for us by zip_fread() already */
    return 0;
}
开发者ID:Hasimir,项目名称:readium-sdk,代码行数:19,代码来源:zip_fseek.c

示例14: zip_open

char *get_contents_zip(char *path, char *name, time_t *last_modified) {
	zip_t *archive = zip_open(path, ZIP_RDONLY, NULL);
	if (archive == NULL) {
		print_zip_err("zip_open", archive);
		return NULL;
	}

	zip_stat_t stat;
	if (zip_stat(archive, name, 0, &stat) < 0) {
		print_zip_err("zip_stat", archive);
		goto close_archive;
	}

	zip_file_t *f = zip_fopen(archive, name, 0);
	if (f == NULL) {
		print_zip_err("zip_fopen", archive);
		goto close_archive;
	}

	if (last_modified != NULL) {
		*last_modified = stat.mtime;
	}

	char *buf = malloc(stat.size + 1);
	if (zip_fread(f, buf, stat.size) < 0) {
		print_zip_err("zip_fread", archive);
		goto free_buf;
	}
	buf[stat.size] = '\0';

	zip_fclose(f);
	zip_close(archive);

	return buf;

free_buf:
	free(buf);
	zip_fclose(f);
close_archive:
	zip_close(archive);

	return NULL;
}
开发者ID:gsnewmark,项目名称:planck,代码行数:43,代码来源:zip.c

示例15: readZipFile

QByteArray readZipFile(const char *archiveName, const char *fileName)
{
    int error = 0;
    zip *archive;
    zip_file *file;
    char buffer[1024];
    int readsize = 0;
    QByteArray ret;

    archive = zip_open(archiveName, 0, &error);

    if (!archive)
    {
        qDebug() << "Error when opening archive" << archiveName;
        return ret;
    }

    file = zip_fopen(archive, fileName, 0);

    if (!file)
    {
        qDebug() << "Error when opening file "<< fileName <<" in archive: " << archiveName <<" : " << zip_strerror(archive);
        zip_close(archive);
        return ret;
    }

    do
    {
        ret.append(buffer, readsize);

        readsize = zip_fread(file, buffer, 1024);
    } while (readsize > 0) ;

    if (readsize < 0)
    {
        qDebug() << "Error when reading file "<< fileName <<" in archive: " << archiveName <<" : " << zip_file_strerror(file);
    }

    zip_fclose(file);
    zip_close(archive);

    return ret;
}
开发者ID:edrex,项目名称:pokemon-online,代码行数:43,代码来源:pokemoninfo.cpp


注:本文中的zip_fread函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。