Archive on the fly, Version 1.2a (alt)

Hinweis: dies ist nicht die neueste Version!

Zurück zur Übersicht

Datei: aotf/vs.tar.php

<?php

/*
    Flocke's "Archive on the Fly"

    Set of PHP classes to create archives on the fly plus a class to extract
    the contents of ZIP files. See the included file README.txt for information
    on how to use it.

    This file: vs.tar.php (class to create tar archives)

    Version 1.2 - always find the latest version at
    http://flocke.vssd.de/prog/code/php/aotf/

    Copyright (C) 2005 Volker Siebert <flocke@vssd.de>
    All rights reserved.

    Permission is hereby granted, free of charge, to any person obtaining a
    copy of this software and associated documentation files (the "Software"),
    to deal in the Software without restriction, including without limitation
    the rights to use, copy, modify, merge, publish, distribute, sublicense,
    and/or sell copies of the Software, and to permit persons to whom the
    Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    DEALINGS IN THE SOFTWARE.
 */

require_once("vs.arc.php");

// These values are compatible with GNU tar for Win32
define('VSTAR_MODE_FILE',      0100666);
define('VSTAR_MODE_DIRECTORY', 0040777);
define('VSTAR_MODE_SYMLINK',   0120777);
define('VSTAR_USTAR',          'ustar  ');
define('VSTAR_USER',           'user');
define('VSTAR_GROUP',          'group');

/*
// Take these values if you get compatibility problems
define('VSTAR_MODE_FILE',      0666);
define('VSTAR_MODE_DIRECTORY', 0777);
define('VSTAR_MODE_SYMLINK',   0777);
define('VSTAR_USTAR',          '');
define('VSTAR_USER',           '');
define('VSTAR_GROUP',          '');
*/

class vsTarFile extends vsArcFile {

    // Reset to create a new archive
    function clear()
    {
        $this->_clear('application/x-tar', '.tar');
    }

    // Add a new entry to the file
    //   NAME is the stored file name
    //   DATE is the modification date/time
    //   FTYPE is one of the VSARC_FTYPE_ constants
    //   DATA is the uncompressed data for files and empty otherwise
    //   LINKTARGET is the target of the symbolic link
    function _add_entry($name, $date, $ftype, &$data, $linktarget = '')
    {
        // Size
        $size = strlen($data);

        // File mode and type flag
        if ($ftype == VSARC_FTYPE_DIR)
        {
            $mode = VSTAR_MODE_DIRECTORY;
            $flag = '5';
        }
        elseif ($ftype == VSARC_FTYPE_SYMLINK)
        {
            $mode = VSTAR_MODE_SYMLINK;
            $flag = '2';
        }
        else
        {
            $mode = VSTAR_MODE_FILE;
            $flag = '0';
        }

        // Construct headers
        $header1 = pack("a100a8a8a8a12A12",
                        $name,
                        sprintf("%6s ",  DecOct($mode)),
                        sprintf("%6s ",  DecOct(0)),
                        sprintf("%6s ",  DecOct(0)),
                        sprintf("%11s ", DecOct($size)),
                        sprintf("%11s",  DecOct($date)));
        $header2 = '        ';
        $header3 = pack("a1a100a8a32a32a183",
                        $flag,
                        $linktarget,
                        VSTAR_USTAR,
                        VSTAR_USER,
                        VSTAR_GROUP,
                        '');

        // Calculate checksum
        $cstr = $header1 . $header2 . $header3;
        $csum = 0;
        for ($i = 0; $i < 512; $i++)
            $csum += ord(substr($cstr, $i, 1));

        $header2 = pack("a8",
                        sprintf("%6s ", DecOct($csum)));

        // Add headers and to the archive data
        $this->_add_data($header1);
        $this->_add_data($header2);
        $this->_add_data($header3);
        $this->_add_data($data);

        // Pad size to full 512 byte blocks
        $rem = (512 - ($size & 511)) & 511;
        if ($rem)
            $this->_add_data(pack("a$rem", ''));
    }

}

?>
Flocke's Garage
Valid HTML 4.01 Transitional Valid CSS!
(C) 2005-2018 Volker Siebert.
Creative Commons-LizenzvertragDer gesamte Inhalt dieser Webseite steht unter einer Creative Commons-Lizenz (sofern nicht anders angegeben).