Skip to content

Instantly share code, notes, and snippets.

@arshidkv12
Last active November 26, 2018 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arshidkv12/15c24203d4765272966cc19c4619f13e to your computer and use it in GitHub Desktop.
Save arshidkv12/15c24203d4765272966cc19c4619f13e to your computer and use it in GitHub Desktop.
file ext
<?php
class archive{
protected $handle_write = null;
protected $handle_read = null;
protected $index = 1;
function compress($file_name, $buffer_size){
$i = 0 ;
if( $this->handle_write == null ){
$this->handle_write = fopen('test.data', 'ab');
}
if( $this->handle_read == null ){
$this->handle_read = fopen( $file_name, 'rb');
}
$size = stat( $file_name );
$block = pack('a255a14', $file_name, $size[7]);
fwrite($this->handle_write, $block);
while (!feof($this->handle_read)) {
$buffer = fread($this->handle_read, $buffer_size);
fwrite($this->handle_write, $buffer);
}
$this->eof = pack( 'a269', '' );
fwrite($this->handle_write, $this->eof);
fclose($this->handle_write);
fclose($this->handle_read);
$this->handle_write = null;
$this->handle_read = null;
$this->index++;
}
function ex( $zip_file ){
$size = 0;
if( $this->handle_read == null ){
$this->handle_read = fopen( $zip_file, 'rb');
}
$flag = true;
$file_name = '';
while( $flag ){
$chunk = fread( $this->handle_read, 255 );
if( ! $chunk ) break;
$data = unpack('a255', $chunk);
echo $file_name = trim($data[1]);
$chunk = fread( $this->handle_read, 14 );
$data = unpack('a14', $chunk);
echo $size = trim( $data[1] );
$offset = 269;
$h = fopen( 'out/'.$file_name, 'ab' );
$sz = 0;
$i = 1;
while( $size >= $sz ){
$buffer_length = ( $size - $sz ) > 512000 ? 512000 : ( $size - $sz );
if( $buffer_length == 0 ) break;
$sz += $buffer_length;
$data = fread( $this->handle_read, $buffer_length );
fwrite( $h, $data);
}
fclose($h);
fread( $this->handle_read, 269 );
}
}
}
$c = new archive;
$c->compress('i/1.mp4', 512000);
$c->compress('i/2.3gp', 512000);
//$c->ex('test.data');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment