Coder Social home page Coder Social logo

taizyeris / archive-tar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mishak87/archive-tar

0.0 2.0 0.0 141 KB

Lightweight implementation of TAR archive reader for PHP with support for gz, bz2, xz (experimental) and files larger then 2 GB

License: Other

archive-tar's Introduction

Archive TAR Reader for PHP

Simple tool for reading TAR archives in PHP. Supports records with size larger then PHP_INT_MAX (slightly less then 2 GB).

Supports only USTAR format. This should be the most used TAR format after 1988.

Gz and bz2 compressions are transparently supported via detection from filename extension.

Installation

Add to your composer.json requirement "mishak/archive-tar": "dev-master".

Examples

List all records in archive

$filename = 'archive.tar';
$reader = new Mishak\ArchiveTar\Reader($filename);
$read->setBuffer(PHP_INT_MAX);
$read->setReadContents(FALSE);
foreach ($reader as $record) {
	print_r($record);
}

Print all file records with contents

$filename = 'archive.tar';
$reader = new Mishak\ArchiveTar\Reader($filename);
foreach ($reader as $record) {
	if (in_array($record['type'], array(\Mishak\ArchiveTar\Reader::REGULAR, \Mishak\ArchiveTar\Reader::AREGULAR), TRUE)) {
		echo $record['filename'], "\n";
		echo $record['contents'], "\n";
	}
}

Print all file records via function callback

This will produce exactly same output as previous example.

$filename = 'archive.tar';
$reader = new Mishak\ArchiveTar\Reader($filename);
$lastRecord = NULL;
$read->setReadContents(function ($record, $chunk, $left, $read) use ($lastRecord) {
	if (!in_array($record['type'], array(\Mishak\ArchiveTar\Reader::REGULAR, \Mishak\ArchiveTar\Reader::AREGULAR), TRUE)) {
		continue;
	}
	if (NULL === $lastRecord || $record['filename'] !== $lastRecord['filename']) {
		if (NULL !== $lastRecord) {
			echo "\n";
		}
		echo $record['filename'], "\n";
	}
	echo $chunk;
	if (!$left) {
		echo "\n";
	}
}
});
foreach ($reader as $record) {
	// don't mind just walking thru...
}

archive-tar's People

Contributors

mishak87 avatar enumag avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.