Skip to content

0.1.1: API changes, improvements

Choose a tag to compare

@wapmorgan wapmorgan released this 21 Sep 05:14
71dad76

Important API changes:

  • Changed algorithm of files list generation in archiveFiles() and addFiles():

    // 1. one file
    $archive->archiveFiles('/var/www/site/abc.log', 'archive.zip'); // => stored as 'abc.log'
    // 2. directory
    $archive->archiveFiles('/var/www/site/runtime/logs', 'archive.zip'); // => directory content stored in archive root
    // 3. list
    $archive->archiveFiles([
          '/var/www/site/abc.log' => 'abc.log', // stored as 'abc.log'
          '/var/www/site/abc.log', // stored as '/var/www/site/abc.log'
          '/var/www/site/runtime/logs' => 'logs', // directory content stored in 'logs' dir
          '/var/www/site/runtime/logs', // stored as '/var/www/site/runtime/logs'
    ], 'archive.zip');
  • Disabled paths expanding in extractFiles() and deleteFiles() by default.

    If you need to expand src/ path to all files within this directory in archive, set second argument $expandFilesList argument to true.

    $archive->extractFiles(__DIR__, 'src/', true);
    $archive->deleteFiles('tests/', true);
  • Added new element in archiveFiles() result in emulation mode. Now it returns an archive with 4 elements: added type element with archive type.

Fixes:

  • Fixed LZW-stream (.tar.Z) wrapper (before it didn't work).
  • Fixed ISO archives reading (before archive size could be calculated wrong).
  • Fixed CAB archives extraction in getFileContent($file) (before it didn't work).
  • Improved extraction in getFileContent($file) for RAR archives by using streams (before it did extract file in temporarily folder, read it and then delete it).

Improvements:

  • Added isFileExists($file): bool method for checking if archive has a file with specific name.
  • Added getFileResource($file): resource method for getting a file descriptor for reading all file content without full extraction in memory.
  • Added canOpenArchive($archiveFileName): bool and canOpenType($archiveFormat): bool static methods to check if specific archive or format can be opened.
  • Added detectArchiveType($fileName): string|false static method to detect (by filename or content) archive type.
  • Added addFile($file, $inArchiveName = null) / addDirectory($directory, $inArchivePath = null) to add one file or one directory, archiveFile($file, $archiveName) / archiveDirectory($directory, $archiveName) to archive one file or directory.

Miscellaneous:

  • Added simple tests.
  • Added phar distribution.