Skip to content

CefZipReader

Header: cef_zip_reader.h
Category: System Utilities

Overview

Tasks, threads, parsers, streams, cookies, URL requests, scheme registration, and constant tables.

CefZipReader

Source File: include/cef_zip_reader.h

Process / Thread Context: Any process — but methods may only be called from the thread that created the object.

Purpose: Streaming reader for ZIP archives, implemented on zlib's unzip API. Walks a cursor file-by-file through the archive and lets the caller open/close/read each file's uncompressed contents.

Methods

static CefRefPtr<CefZipReader> Create(CefRefPtr<CefStreamReader> stream)

Parameters:

  • stream: reader supplying the ZIP bytes (must be seekable / buffered).

Return Value: New reader; creator-thread only thereafter.

Threading Constraint: Any thread (creation).

virtual bool MoveToFirstFile()

Return Value: cursor → first file. Creator thread.

Threading Constraint: Threading constraint not specified in source.

virtual bool MoveToNextFile()

Return Value: cursor → next file. Creator thread.

Threading Constraint: Threading constraint not specified in source.

virtual bool MoveToFile(const CefString& fileName, bool caseSensitive)

Parameters:

  • fileName: file name to find; caseSensitive: case-sensitivity flag.

Return Value: true if cursor positioned.

Threading Constraint: Creator thread.

virtual bool Close()

Return Value: close archive (cleanup on correct thread). Creator thread.

Threading Constraint: Threading constraint not specified in source.

virtual CefString GetFileName()

Return Value: file name at cursor. Creator thread.

Threading Constraint: Threading constraint not specified in source.

virtual int64_t GetFileSize()

Return Value: uncompressed size in bytes. Creator thread.

Threading Constraint: Threading constraint not specified in source.

virtual CefBaseTime GetFileLastModified()

Return Value: last-modified timestamp. Creator thread.

Threading Constraint: Threading constraint not specified in source.

virtual bool OpenFile(const CefString& password)

Parameters:

  • password: optional (optional_param) password for encrypted entries.

Return Value: true if file opened for reading uncompressed data.

Threading Constraint: Creator thread.

virtual bool CloseFile()

Return Value: close the currently open file. Creator thread.

Threading Constraint: Threading constraint not specified in source.

virtual int ReadFile(void* buffer, size_t bufferSize)

Parameters:

  • buffer: destination; bufferSize: capacity.

Return Value: < 0 on error, 0 at EOF, else number of bytes read.

Threading Constraint: Creator thread.

virtual int64_t Tell()

Return Value: current byte offset within the uncompressed file. Creator thread.

Threading Constraint: Threading constraint not specified in source.

virtual bool Eof()

Return Value: true at end of file. Creator thread.

Threading Constraint: Threading constraint not specified in source.

Usage Example

cpp
// Extract a single known file from an archive on a background thread.
CefRefPtr<CefStreamReader> sr = CefStreamReader::CreateForFile("archive.zip");
CefRefPtr<CefZipReader> zip = CefZipReader::Create(sr);
if (zip->MoveToFile("config/settings.json", /*caseSensitive=*/false)) {
  if (zip->OpenFile("")) {
    std::string out;
    out.resize(zip->GetFileSize());
    int64_t total = 0;
    while (!zip->Eof()) {
      int n = zip->ReadFile(&out[total], out.size() - total);
      if (n <= 0) break;
      total += n;
    }
    zip->CloseFile();
    // 'out' now contains the uncompressed JSON bytes.
  }
}
zip->Close();

Derived from the CEF C++ headers — © Marshall A. Greenblatt, Google Inc. & contributors (BSD-style license). Not an official CEF project.