Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teaching zipstreamer new tricks: addFileFromString & addFileOpen/Write/Close #36

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
be6e578
Fix invalid reference to 'this' in static
Jul 14, 2016
c08fb3b
Remove trailing close-php (best practice)
Jul 14, 2016
b9e3f75
phpstorm project (no workspace)
Jul 14, 2016
5bf1913
Housekeeping
Jul 14, 2016
c7b7aa3
Teach zipstreamer to create file from data (string) and chunk by chunk.
Jul 14, 2016
7174e66
Docs update
Jul 14, 2016
4c93aa8
No need for inspection profile info.
Jul 14, 2016
836079c
Add inspection profile to ignores.
Jul 14, 2016
a769a31
composer improvements.
Jul 14, 2016
71f6ea2
docs for addFileOpen/Write/Close
Jul 14, 2016
a9a551b
Name according to my fork
Jul 19, 2016
c6c115d
Split up into PSR-4 format and fix tests. (Including kill off 'lib' f…
Jul 19, 2016
828a585
Add in many of the other compression method constants, and use decima…
Jul 20, 2016
ac10362
Switch to using 1<<N notation to make the bit numbers easier to see, …
Jul 20, 2016
8e150d8
Fix handling of GPFLAGS::ADD and crc calculation.
Jul 20, 2016
13ff0f5
Fix test code to test with the psr-4 layout and with files that don't…
Jul 20, 2016
7375e21
Housekeeping
Jul 20, 2016
7bbd947
Fix repo url
Jul 20, 2016
2f00629
Variable name outStream caps here but not elsewhere.
Jul 27, 2016
4d4af72
TRUE/True/true consistency; some re-spacing.
Jul 27, 2016
df2990d
Work on Docblocks
Jul 27, 2016
a17bd0a
Recast nested 'if' as a switch
Jul 27, 2016
c122dad
Code block reindenting.
Jul 27, 2016
8253118
FLush the output stream more completely.
Jul 27, 2016
4b629d6
Update composer.json
rivimey Mar 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea/atlassian-ide-plugin.xml
.idea/workspace.xml
.idea/vcs.xml
.idea/tasks.xml
.idea/inspectionProfiles/Project_Default.xml
/vendor
8 changes: 8 additions & 0 deletions .idea/PHPZipStreamer.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/composerJson.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ before_install:
- sh -c "mkdir -p ${TRAVIS_BUILD_DIR}/travis/module-cache/`php-config --vernum`"

before_script:
- ./test/travis/php-modules-install.sh
- ./tests/travis/php-modules-install.sh

script:
- phpunit --configuration test/phpunit.xml
- phpunit --configuration phpunit.xml

cache:
directories:
Expand Down
100 changes: 99 additions & 1 deletion MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,39 @@ $zip->finalize();

```

Add a single file (here, html text) in immediate mode:
```php
require("src/ZipStreamer.php");

# initialize ZipStreamer object (ZipStreamer has it's own namespace)
$zip = new ZipStreamer\ZipStreamer();

$data = "<html><head><title>Hello World</title></head><body><h1>Hello World</h1></body></html>";
$zip->addFileFromString($data, 'test1.htm');

# finalize zip file. Nothing can be added any more.
$zip->finalize();

```

Add a single file (here, html text) using the chunk interface, to enable
in-flight file streaming:
```php
require("src/ZipStreamer.php");

# initialize ZipStreamer object (ZipStreamer has it's own namespace)
$zip = new ZipStreamer\ZipStreamer();

$zip->addFileOpen('test1.htm');
$data = "<html><head><title>Hello World</title></head><body><h1>Hello World</h1></body></html>";
$zip->addFileWrite($data);
$zip->addFileClose();

# finalize zip file. Nothing can be added any more.
$zip->finalize();

```

Characteristics
---------------

Expand All @@ -64,6 +97,10 @@ deflate (the zip standard) compression can be enabled and/or disabled globally
and per file. Without pecl_http extension, it is still possible to enable
deflate compression, but with compression level 0, so there is no actual
compression.
Note: The pecl_http extension is also available in some OS repos as 'php-http'.
* addFileFromString sets the data length and CRC in the file header while
addFileFromStream and addFileOpen/addFileWrite/addFileClose both create a
blank file header and fill in the length afterwards, as allowed by the zip spec.

API Documentation
-----------------
Expand Down Expand Up @@ -125,6 +162,68 @@ Add a file to the archive at the specified location and file name.
######Returns
bool Success

```
addFileFromString(string $data, string $filePath, array $options) : bool
```

Add a file to the archive at the specified location and file name.

######Parameters
* string *$data* The file contents to store.
* string *$filePath* Filepath and name to be used in the archive.
* array *options* (optional) additional options. Valid options are:
* int *$timestamp* Timestamp for the file (default: current time)
* string *$comment* comment to be added for this file (default: none)
* int *compress*: compression method (override global option for this
file)
* int *level*: compression level (override global option for this file)

######Returns
bool Success

```
addFileOpen(string $filePath, array $options) : bool
```

Start the process of adding a file chunk by chunk.

This call must be followed by 0 or more calls to addFileWrite(), and then one
call to addFileClose(). There is no support for multiple simultaneously active
files.

######Parameters
* string *$filePath* Filepath and name to be used in the archive.
* array *options* (optional) additional options. Valid options are:
* int *$timestamp* Timestamp for the file (default: current time)
* string *$comment* comment to be added for this file (default: none)
* int *compress*: compression method (override global option for this
file)
* int *level*: compression level (override global option for this file)

######Returns
bool Success

```
addFileWrite(string $data) : bool
```

Append more data to a file being written by addFileOpen().

######Parameters
* string *$data* The file contents to store.

######Returns
bool Success

```
addFileClose() : bool
```

Close a file being written by addFileOpen() and append relevant metadata.

######Returns
bool Success

```
addEmptyDir(string $directoryPath, array $options) : bool
```
Expand All @@ -150,4 +249,3 @@ A closed archive can no longer have new files added to it. After closing, the zi

######Returns
bool Success

20 changes: 15 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "mcnetic/zipstreamer",
"name": "rivimey/zipstreamer",
"type": "library",
"description": "Stream zip files without i/o overhead",
"keywords": ["zip", "stream"],
Expand All @@ -17,19 +17,29 @@
"name": "Lukas Reschke",
"email": "[email protected]",
"role": "Contributor"
},{
"name": "Ruth Ivimey-Cook",
"email": "[email protected]",
"role": "Contributor"
}
],
"repositories": [ {
"type": "vcs",
"url": "https://github.com/McNetic/PHPZipStreamer"
"url": "https://github.com/rivimey/PHPZipStreamer.git"
}
],
],
"require": {
"php": ">=5.3.0"
"php": ">=5.3.0",
"ext-mbstring": "*",
"ext-http": "~2.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.30",
"ext-xdebug": "*"
},
"autoload": {
"psr-4": {
"ZipStreamer\\": "src/"
"Rivimey\\ZipStreamer\\": "src/"
}
}
}
Loading