Reference Documentation
This section contains reference documentation for libzip. It is meant to be comprehensive and detailed, covering all the functions, features, and components, but may not be the best place to start for new users.
The concepts and design decisions of libzip are explained in the Explanations section.
To get started, please refer to the Tutorials section. For practical instructions, see the How-To Guides section.
Command Line Tools
libzip includes the following command line tools:
- zipcmp
- Compare content of two zip archives or directories and report differences.
- zipmerge
- Merge multiple zip archives into one.
- ziptool
- Perform various operations on zip archives, including getting information about them, extracting or adding files.
Library
The following sections describe the functions and data types provided by libzip. They are organized by use case, roughly in order of importance or in the expected calling order. Each function is only listed once, so some functions listed in a previous section may also apply to later sections.
If you are looking for a specific function, use the search box in the header, or use your browser's search functionality to find it on this page.
Reading Zip Archives
This section covers the function used for reading zip archives without modifying them.
Opening and Closing Archives
- zip_t
- The main data type representing a zip archive.
- zip_open, zip_open_from_source
- Open a zip archive.
- zip_fdopen
- Open a zip archive from a file descriptor.
- zip_close
- Close a zip archive, writing any changes to disk.
Getting Archive Attributes
- zip_get_archive_comment
- Get the comment of a zip archive.
- zip_get_archive_flag
- Check one of the flags of a zip archive.
- zip_get_num_entries
- Get the number of entries in a zip archive.
Finding Files
- zip_name_locate
- Get the index of a file by its name.
Getting File Attributes
- zip_stat_init
- Initialize a
zip_stat_tstructure. - zip_file_get_comment
- Get the comment of a file.
- zip_file_get_external_attributes
- Get the external attributes of a file.
- zip_get_name
- Get the name of a file.
- zip_file_extra_field_get, zip_file_extra_field_get_by_id
- Get an extra field from a file.
- zip_file_extra_fields_count, zip_file_extra_fields_count_by_id
- Get the number of extra fields for a file.
Reading File Data
These are convenience functions wrapping a zip_source_t for reading file data. You can also get the source directly with zip_source_zip_file.
- zip_file_t
- A file opened for reading.
- zip_fopen, zip_fopen_index
- Open a file for reading.
- zip_fopen_encrypted, zip_fopen_encrypted_index
- Open an encrypted file for reading with the specified password.
- zip_fread
- Read data from a file.
- zip_fseek, zip_file_is_seekable
- Seek to a position in a file.
- zip_ftell
- Get the current position in a file.
- zip_fclose
- Close a file.
Miscellaneous
- zip_set_default_password
- Set the default password for encrypted files in a zip archive.
- zip_compression_method_supported
- Check if a compression method is supported.
- zip_encryption_method_supported
- Check if an encryption method is supported.
Creating and Modifying Zip Archives
This section covers additional functions used for creating and modifying zip archives. For the functions to provide data to be added, see the Creating Sources section below.
Changing Archive Attributes
- zip_set_archive_comment
- Set the comment of a zip archive.
- zip_set_archive_flag
- Set or clear one of the flags of a zip archive.
Changing Files and Directories
- zip_file_add, zip_file_replace
- Add or replace a file in a zip archive.
- zip_file_rename
- Rename a file in a zip archive.
- zip_delete
- Delete a file from a zip archive.
- zip_dir_add
- Add a directory to a zip archive.
- zip_set_file_compression
- Set the compression method of a file in a zip archive.
- zip_file_set_encryption
- Set the encryption method of a file in a zip archive.
- zip_file_set_comment
- Set the comment of a file in a zip archive.
- zip_file_set_mtime, zip_file_set_dostime
- Set the modification time of a file in a zip archive.
- zip_file_set_external_attributes
- Set the external attributes of a file in a zip archive.
- zip_file_extra_field_set
- Set an extra field for a file in a zip archive.
- zip_file_extra_field_delete, zip_file_extra_field_delete_by_id
- Delete an extra field from a file in a zip archive.
Reverting Changes
- zip_discard
- Discard all changes to a zip archive and close it.
- zip_unchange_all
- Discard all file data changes to a zip archive.
- zip_unchange_archive
- Discard all changes to a zip archive.
- zip_unchange
- Discard changes to a file in a zip archive.
Progress Callbacks
- zip_register_cancel_callback_with_state
- Register a callback to allow cancelling zip_close().
- zip_register_progress_callback_with_state
- Register a callback to report progress during zip_close().
Error Handling
This section covers the functions and data types used for error handling in libzip.
- zip_error_t
- A structure representing an error.
- zip_errors
- List and description of all error codes.
- zip_strerror, zip_file_strerror
- Get a human-readable string describing the error of a
zip_file_t. - zip_error_clear, zip_file_error_clear
- Clear error state of an archive or file.
- zip_get_error
- Get the error information of a
zip_t. - zip_file_get_error
- Get the error information of a
zip_file_t. - zip_error_strerror
- Get a human-readable string describing the error.
- zip_error_system_type
- Get the type of the system error code in a
zip_error_t. - zip_error_code_system
- Get the operating system part of a
zip_error_t. - zip_error_code_zip
- Get the libzip part of a
zip_error_t. - zip_error_init, zip_error_init_with_code
- Initialize a
zip_error_tstructure. - zip_error_fini
- Free resources used by a
zip_error_t. - zip_error_set
- Fill in a
zip_error_tstructure.
Sources
Sources are the abstraction libzip uses to represent file data. They are used for reading data from zip archives and providing data to be added to zip archives. Common sources are provided for files and memory buffers, and custom sources can be implemented by the user.
Creating Sources
- zip_source_t
- The data structure representing a source.
- zip_source_buffer, zip_source_buffer_create
- Create a source from a memory buffer.
- zip_source_file, zip_source_file_create
- Create a source from a file.
- zip_source_filep, zip_source_filep_create
- Create a source from a
FILEpointer. - zip_source_win32a, zip_source_win32a_create
- Create a source from a file with ANSI name. (Windows only)
- zip_source_win32handle, zip_source_win32handle_create
- Create a source from a Windows file handle. (Windows only)
- zip_source_win32w, zip_source_win32w_create
- Create a source from a file with UTF-16 name. (Windows only)
- zip_source_window_create
- Create a source from a section of another source.
- zip_source_zip_file, zip_source_zip_file_create
- Create a source from a file in a zip archive.
Freeing Sources
- zip_source_free
- Decrease a source's reference count and free it if it reaches zero.
- zip_source_keep
- Keep ownership of a source by increasing its reference count.
- zip_source_is_deleted
- Check if a source has been deleted.
Reading from a Source
- zip_source_stat
- Get information about a source.
- zip_source_open
- Start reading from a source.
- zip_source_read
- Read data from a source.
- zip_source_is_seekable
- Check if a source is seekable.
- zip_source_seek
- Seek to a position in a source.
- zip_source_tell
- Get the current position in a source.
- zip_source_close
- Stop reading from a source.
Writing to a Source
- zip_source_begin_write, zip_source_begin_write_cloning
- Prepare a source for writing.
- zip_source_write
- Write data to a source.
- zip_source_seek_write
- Seek to a position in a source for writing.
- zip_source_tell_write
- Get the current position in a source for writing.
- zip_source_commit_write
- Commit changes written to a source.
- zip_source_rollback_write
- Discard changes written to a source.
Implementing a Source
- zip_source_function, zip_source_function_create
- Create a source from a callback function.
- zip_source_layered, zip_source_layered_create
- Create a source based on another source and a callback function.
- ZIP_SOURCE_GET_ARGS
- Validate and type cast arguments passed to a custom source callback.
- zip_source_make_command_bitmap
- Compute bitmap of supported commands from a list of commands.
- zip_error_to_data
- Convert a
zip_error_tto a value suitable forZIP_SOURCE_ERROR. - zip_source_seek_compute_offset
- Compute the offset to seek to in a source based on seek arguments.
- zip_file_attributes_init
- Initialize a
zip_file_attributes_tstructure.
Getting Library Version
- zip_libzip_version
- Get the version of libzip.
Deprecated Functions
These functions are deprecated and should not be used in new code. They may be removed in a future major release. They are listed here for reference and to help with migrating old code; replacement functions are suggested for each of them.
- zip_add
- Add a file to a zip archive; use zip_file_add instead.
- zip_add_dir
- Add a directory to a zip archive; use zip_dir_add instead.
- zip_error_get
- Get the error information of a
zip_t; use zip_get_error instead. - zip_error_to_str
- Get a human-readable string describing the error; use zip_error_strerror instead.
- zip_error_get_sys_type
- Get the type of the system error code in a
zip_error_t; use zip_error_system_type instead. - zip_get_file_comment
- Get the comment of a file in a zip archive; use zip_file_get_comment instead.
- zip_get_num_files
- Get the number of files in a zip archive; use zip_get_num_entries instead.
- zip_register_progress_callback
- Register a callback to report progress during zip_close(); use zip_register_progress_callback_with_state instead.
- zip_rename
- Rename a file in a zip archive; use zip_file_rename instead.
- zip_set_file_comment
- Set the comment of a file in a zip archive; use zip_file_set_comment instead.
- zip_source_zip
- Create a
zip_source_tfrom a zip archive; use zip_source_zip_file instead.