Skip to content

xenocrat/var2zip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 

Repository files navigation

What is this?

var2zip is a PHP class for creating simple Zip archives in RAM.

Requirements

  • PHP 8.0+
  • ZLIB extension (optional)

Limitations

  • Maximum entry size is 4 GiB
  • Directories are not supported

Usage

Create a new instance:

$var2zip = new \xenocrat\var2zip();

Add an entry read from disk:

$file = file_get_contents("README.md");
$var2zip->add("README.md", $file);

Add an entry with last-modified timestamp:

$modified = strtotime("1982-09-09T20:19:11Z");
$var2zip->add("hello.txt", "Hello, world!", $modified);

Export the Zip archive and write to disk:

$zip = $var2zip->export();
file_put_contents("archive.zip", $zip);

Methods

add

Description

public var2zip::add(
    string $name,
    string $contents
    int $modified = null
): int

Adds a file entry to the archive.

Parameters

  • name

    The file name as a UTF-8 encoded string not exceeding 65535 bytes.

  • contents

    A complete file as a string of data not exceeding 4294967295 bytes.

  • modified

    A unix timestamp representing the last-modified time of the file.

Return Values

Returns an integer representing the total number of entries in the archive.

export

Description

public var2zip::export(
    int $compression_level = -1
): string|false

Exports the file entries to Zip archive.

Parameters

  • compression_level

    The compression level, from 0 (none) to 9 (maximum). Defaults to 6.

Return Values

Returns a complete Zip archive as a string of data, or false if there are no file entries to export.

About

A PHP class for creating simple Zip archives in RAM.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages