Skip to content

Commit

Permalink
Merge pull request #2 from owncloud/fix-composer
Browse files Browse the repository at this point in the history
Fix composer & add unit testing on travis
  • Loading branch information
DeepDiver1975 committed Sep 25, 2015
2 parents a2e7981 + 16caf5f commit 0b9e800
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 132 deletions.
9 changes: 9 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
filter:
excluded_paths:
- 'vendor/*'

imports:
- php

tools:
external_code_coverage: true
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
language: php
php:
# - 5.3
- 5.4
- 5.5
- 5.6
- 7.0

branches:
only:
- master

install:
- composer install --dev --no-interaction

script:
- mkdir -p build/logs
- cd tests
- phpunit --coverage-clover ../build/logs/clover.xml --configuration phpunit.xml

after_script:
# Create coverage report
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
44 changes: 30 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
{
"name": "deepdiver1975/tarstreamer",
"type": "library",
"description": "A library for dynamically streaming dynamic tar files without the need to have the complete file stored on the server.",
"keywords": ["tar", "archive", "stream", "php"],
"homepage": "https://github.com/DeepDiver1975/TarStreamer",
"license": "MIT",
"require": {
"php": ">=5.3.8"
},
"autoload": {
"psr-4": {
"DeepDiver1975\\TarStreamer\\": "src/"
}
}
"name": "owncloud/tarstreamer",
"type": "library",
"description": "A library for dynamically streaming dynamic tar files without the need to have the complete file stored on the server.",
"keywords": [
"tar",
"archive",
"stream",
"php"
],
"homepage": "https://github.com/owncloud/TarStreamer",
"license": "MIT",
"require": {
"php": ">=5.3.8"
},
"autoload": {
"psr-4": {
"ownCloud\\TarStreamer\\": "src/"
}
},
"archive": {
"exclude": [
"test",
"tests"
]
},
"require-dev": {
"phpunit/phpunit": "^4.8",
"pear/pear-core-minimal": "v1.10.0alpha2",
"pear/archive_tar": "~1.4"
}
}
29 changes: 15 additions & 14 deletions src/TarStreamer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DeepDiver1975\TarStreamer;
namespace ownCloud\TarStreamer;

class TarStreamer {

Expand All @@ -11,7 +11,7 @@ class TarStreamer {
/**
* Process in 1 MB chunks
*/
protected $blockSize = 1 * 1024 * 1024;
protected $blockSize = 1048576;
protected $outStream;
protected $needHeaders = false;

Expand All @@ -22,9 +22,9 @@ class TarStreamer {
*/
public function __construct($options = []){
if (isset($options['outstream'])){
$this->outstream = $options['outstream'];
$this->outStream = $options['outstream'];
} else {
$this->outstream = fopen('php://output', 'w');
$this->outStream = fopen('php://output', 'w');
// turn off output buffering
while (ob_get_level() > 0){
ob_end_flush();
Expand Down Expand Up @@ -78,9 +78,10 @@ public function sendHeaders($archiveName = 'archive.tar', $contentType = 'applic
/**
* Add a file to the archive at the specified location and file name.
*
* @param string $stream Stream to read data from
* @param string $filePath Filepath and name to be used in the archive.
* @param array $options Optional, additional options
* @param resource $stream Stream to read data from
* @param string $filePath Filepath and name to be used in the archive.
* @param int $size
* @param array $options Optional, additional options
* Valid options are:
* * int timestamp: timestamp for the file (default: current time)
* @return bool $success
Expand Down Expand Up @@ -133,7 +134,7 @@ public function finalize(){
$this->send(pack('a1024', ''));

// flush the data to the output
fflush($this->outstream);
fflush($this->outStream);
return true;
}

Expand Down Expand Up @@ -205,19 +206,19 @@ protected function initFileStreamTransfer($name, $type, $size, $opt = []){
/**
* Stream the next part of the current file stream.
*
* @param $data raw data to send
* @param string $data raw data to send
*/
protected function streamFilePart($data){
// send data
$this->send($data);

// flush the data to the output
fflush($this->outstream);
fflush($this->outStream);
}

/**
* Complete the current file stream
*
* @param $size
*/
protected function completeFileStream($size){
// ensure we pad the last block so that it is 512 bytes
Expand All @@ -226,7 +227,7 @@ protected function completeFileStream($size){
}

// flush the data to the output
fflush($this->outstream);
fflush($this->outStream);
}

/**
Expand All @@ -240,13 +241,13 @@ protected function send($data){
}
$this->needHeaders = false;

fwrite($this->outstream, $data);
fwrite($this->outStream, $data);
}

/**
* Create a format string and argument list for pack(), then call pack() and return the result.
*
* @param array key being the format string and value being the data to pack
* @param array $fields key being the format string and value being the data to pack
* @return string binary packed data returned from pack()
*/
protected function packFields($fields){
Expand Down
5 changes: 0 additions & 5 deletions test/testdata/lorem.txt

This file was deleted.

3 changes: 0 additions & 3 deletions test/testdata/lorem2

This file was deleted.

24 changes: 0 additions & 24 deletions test/testdata/more ipsum/lorem2.txt

This file was deleted.

72 changes: 0 additions & 72 deletions test/usage.php

This file was deleted.

50 changes: 50 additions & 0 deletions tests/Streamer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace ownCloud\TarStreamer\Tests;

use Archive_Tar;
use ownCloud\TarStreamer\TarStreamer;
use PHPUnit_Framework_TestCase;

class Streamer extends PHPUnit_Framework_TestCase
{
/** @var string */
private $archive;

/** @var TarStreamer */
private $streamer;

public function setUp() {
$this->archive = tempnam('/tmp' , 'tar');
$this->streamer = new TarStreamer(
['outstream' => fopen($this->archive, 'w')]
);
}

/**
* @dataProvider providesNameAndData
* @param $fileName
* @param $data
*/
public function testSimpleFile($fileName, $data) {
$dataStream = fopen('data://text/plain,'.$data, 'r');
$this->streamer->addFileFromStream($dataStream, $fileName, 10);
$this->streamer->finalize();

$this->assertTar($fileName, $data);
}

public function providesNameAndData() {
return [
['foo.bar', '1234567890'],
// ['foobar1234foobar1234foobar1234foobar1234foobar1234foobar1234foobar1234foobar1234foobar1234foobar1234.txt', 'abcdefgh']
];
}

private function assertTar($file, $data)
{
$arc = new Archive_Tar($this->archive);
$content = $arc->extractInString($file);
$this->assertEquals($data, $content);
}
}
3 changes: 3 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

require_once __DIR__.'/../vendor/autoload.php';
6 changes: 6 additions & 0 deletions tests/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<phpunit bootstrap="bootstrap.php">
<testsuite name='TarStreamer'>
<directory suffix='.php'>./</directory>
</testsuite>
</phpunit>

0 comments on commit 0b9e800

Please sign in to comment.