Skip to content

Commit 3b628c2

Browse files
author
kamijo
committed
Init files
0 parents  commit 3b628c2

20 files changed

+2457
-0
lines changed

CREDITS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lz4

EXPERIMENTAL

Whitespace-only changes.

LICENSE

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
--------------------------------------------------------------------
2+
The PHP License, version 3.01
3+
Copyright (c) 1999 - 2012 The PHP Group. All rights reserved.
4+
--------------------------------------------------------------------
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, is permitted provided that the following conditions
8+
are met:
9+
10+
1. Redistributions of source code must retain the above copyright
11+
notice, this list of conditions and the following disclaimer.
12+
13+
2. Redistributions in binary form must reproduce the above copyright
14+
notice, this list of conditions and the following disclaimer in
15+
the documentation and/or other materials provided with the
16+
distribution.
17+
18+
3. The name "PHP" must not be used to endorse or promote products
19+
derived from this software without prior written permission. For
20+
written permission, please contact [email protected].
21+
22+
4. Products derived from this software may not be called "PHP", nor
23+
may "PHP" appear in their name, without prior written permission
24+
from [email protected]. You may indicate that your software works in
25+
conjunction with PHP by saying "Foo for PHP" instead of calling
26+
it "PHP Foo" or "phpfoo"
27+
28+
5. The PHP Group may publish revised and/or new versions of the
29+
license from time to time. Each version will be given a
30+
distinguishing version number.
31+
Once covered code has been published under a particular version
32+
of the license, you may always continue to use it under the terms
33+
of that version. You may also choose to use such covered code
34+
under the terms of any subsequent version of the license
35+
published by the PHP Group. No one other than the PHP Group has
36+
the right to modify the terms applicable to covered code created
37+
under this License.
38+
39+
6. Redistributions of any form whatsoever must retain the following
40+
acknowledgment:
41+
"This product includes PHP software, freely available from
42+
<http://www.php.net/software/>".
43+
44+
THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
45+
ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
46+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP
48+
DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
49+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
50+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55+
OF THE POSSIBILITY OF SUCH DAMAGE.
56+
57+
--------------------------------------------------------------------
58+
59+
This software consists of voluntary contributions made by many
60+
individuals on behalf of the PHP Group.
61+
62+
The PHP Group can be contacted via Email at [email protected].
63+
64+
For more information on the PHP Group and the PHP project,
65+
please see <http://www.php.net>.
66+
67+
PHP includes the Zend Engine, freely available at
68+
<http://www.zend.com>.

LICENSE.lz4

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
LZ4 - Fast LZ compression algorithm
2+
Copyright (C) 2011-2012, Yann Collet.
3+
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following disclaimer
13+
in the documentation and/or other materials provided with the
14+
distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
28+
You can contact the author at :
29+
- LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
30+
- LZ4 source repository : http://code.google.com/p/lz4/

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# LZ4 Extension for PHP #
2+
3+
This extension allows LZ4.
4+
5+
## Build ##
6+
7+
% phpize
8+
% ./configure
9+
% make
10+
% make install
11+
12+
## Configration ##
13+
14+
lz4.ini:
15+
16+
extension=lz4.so
17+
18+
## Function ##
19+
20+
* lz4\_compress — LZ4 compression
21+
* lz4\_uncompress — LZ4 decompression
22+
23+
24+
### lz4\_compress — LZ4 compression ###
25+
26+
#### Description ####
27+
28+
string **lz4\_compress** ( string _$data_ [ , bool _$high_ = false ] )
29+
30+
LZ4 compression.
31+
32+
#### Pameters ####
33+
34+
* _data_
35+
36+
The string to compress.
37+
38+
* _high_
39+
40+
High Compression Mode.
41+
42+
#### Return Values ####
43+
44+
Returns the compressed data or FALSE if an error occurred.
45+
46+
47+
### lz4\_uncompress — LZ4 decompression ###
48+
49+
#### Description ####
50+
51+
string **lz4\_uncompress** ( string _$data_ [ , long _$maxsize_ ] )
52+
53+
LZ4 decompression.
54+
55+
#### Pameters ####
56+
57+
* _data_
58+
59+
The compressed string.
60+
61+
* _maxsize_
62+
63+
Allocate size output data.
64+
65+
#### Return Values ####
66+
67+
Returns the decompressed data or FALSE if an error occurred.
68+
69+
## Examples ##
70+
71+
$data = lz4_compress('test');
72+
73+
lz4_uncompress($data);

config.m4

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
dnl config.m4 for extension lz4
2+
3+
dnl Check PHP version:
4+
AC_MSG_CHECKING(PHP version)
5+
if test ! -z "$phpincludedir"; then
6+
PHP_VERSION=`grep 'PHP_VERSION ' $phpincludedir/main/php_version.h | sed -e 's/.*"\([[0-9\.]]*\)".*/\1/g' 2>/dev/null`
7+
elif test ! -z "$PHP_CONFIG"; then
8+
PHP_VERSION=`$PHP_CONFIG --version 2>/dev/null`
9+
fi
10+
11+
if test x"$PHP_VERSION" = "x"; then
12+
AC_MSG_WARN([none])
13+
else
14+
PHP_MAJOR_VERSION=`echo $PHP_VERSION | sed -e 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/g' 2>/dev/null`
15+
PHP_MINOR_VERSION=`echo $PHP_VERSION | sed -e 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/g' 2>/dev/null`
16+
PHP_RELEASE_VERSION=`echo $PHP_VERSION | sed -e 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/g' 2>/dev/null`
17+
AC_MSG_RESULT([$PHP_VERSION])
18+
fi
19+
20+
if test $PHP_MAJOR_VERSION -lt 5; then
21+
AC_MSG_ERROR([need at least PHP 5 or newer])
22+
fi
23+
24+
PHP_ARG_ENABLE(lz4, whether to enable lz4 support,
25+
[ --enable-lz4 Enable lz4 support])
26+
27+
if test "$PHP_LZ4" != "no"; then
28+
29+
PHP_NEW_EXTENSION(lz4, lz4.c lz4/lz4.c lz4/lz4hc.c, $ext_shared)
30+
31+
ifdef([PHP_INSTALL_HEADERS],
32+
[
33+
PHP_INSTALL_HEADERS([ext/lz4/], [php_lz4.h])
34+
], [
35+
PHP_ADD_MAKEFILE_FRAGMENT
36+
])
37+
fi

lz4.c

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
2+
#ifdef HAVE_CONFIG_H
3+
#include "config.h"
4+
#endif
5+
6+
#include "php.h"
7+
#include "php_ini.h"
8+
#include "ext/standard/info.h"
9+
#include "php_lz4.h"
10+
11+
/* lz4 */
12+
#include "lz4/lz4.h"
13+
#include "lz4/lz4hc.h"
14+
15+
static ZEND_FUNCTION(lz4_compress);
16+
static ZEND_FUNCTION(lz4_uncompress);
17+
18+
ZEND_BEGIN_ARG_INFO_EX(arginfo_lz4_compress, 0, 0, 1)
19+
ZEND_ARG_INFO(0, data)
20+
ZEND_ARG_INFO(0, high)
21+
ZEND_END_ARG_INFO()
22+
23+
ZEND_BEGIN_ARG_INFO_EX(arginfo_lz4_uncompress, 0, 0, 1)
24+
ZEND_ARG_INFO(0, data)
25+
ZEND_ARG_INFO(0, max)
26+
ZEND_END_ARG_INFO()
27+
28+
static const zend_function_entry lz4_functions[] = {
29+
ZEND_FE(lz4_compress, arginfo_lz4_compress)
30+
ZEND_FE(lz4_uncompress, arginfo_lz4_uncompress)
31+
ZEND_FE_END
32+
};
33+
34+
ZEND_MINFO_FUNCTION(lz4)
35+
{
36+
php_info_print_table_start();
37+
php_info_print_table_row(2, "LZ4 support", "enabled");
38+
php_info_print_table_row(2, "Extension Version", LZ4_EXT_VERSION);
39+
php_info_print_table_end();
40+
}
41+
42+
zend_module_entry lz4_module_entry = {
43+
#if ZEND_MODULE_API_NO >= 20010901
44+
STANDARD_MODULE_HEADER,
45+
#endif
46+
"lz4",
47+
lz4_functions,
48+
NULL,
49+
NULL,
50+
NULL,
51+
NULL,
52+
ZEND_MINFO(lz4),
53+
#if ZEND_MODULE_API_NO >= 20010901
54+
LZ4_EXT_VERSION,
55+
#endif
56+
STANDARD_MODULE_PROPERTIES
57+
};
58+
59+
#ifdef COMPILE_DL_LZ4
60+
ZEND_GET_MODULE(lz4)
61+
#endif
62+
63+
static ZEND_FUNCTION(lz4_compress)
64+
{
65+
zval *data;
66+
char *output;
67+
int output_len;
68+
zend_bool high = 0;
69+
70+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
71+
"z|b", &data, &high) == FAILURE) {
72+
RETURN_FALSE;
73+
}
74+
75+
if (Z_TYPE_P(data) != IS_STRING) {
76+
zend_error(E_WARNING,
77+
"lz4_compress : expects parameter to be string.");
78+
RETURN_FALSE;
79+
}
80+
81+
output = (char *)emalloc(LZ4_compressBound(Z_STRLEN_P(data)));
82+
if (!output) {
83+
zend_error(E_WARNING, "lz4_compress : memory error");
84+
RETURN_FALSE;
85+
}
86+
87+
if (high) {
88+
output_len = LZ4_compressHC(Z_STRVAL_P(data), output, Z_STRLEN_P(data));
89+
} else {
90+
output_len = LZ4_compress(Z_STRVAL_P(data), output, Z_STRLEN_P(data));
91+
}
92+
93+
if (output_len <= 0) {
94+
RETVAL_FALSE;
95+
} else {
96+
RETVAL_STRINGL(output, output_len, 1);
97+
}
98+
99+
efree(output);
100+
}
101+
102+
static ZEND_FUNCTION(lz4_uncompress)
103+
{
104+
zval *data;
105+
int output_len;
106+
char *output;
107+
long max_size = -1;
108+
int i = 1;
109+
110+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
111+
"z|l", &data, &max_size) == FAILURE) {
112+
RETURN_FALSE;
113+
}
114+
115+
if (Z_TYPE_P(data) != IS_STRING) {
116+
zend_error(E_WARNING,
117+
"lz4_uncompress : expects parameter to be string.");
118+
RETURN_FALSE;
119+
}
120+
121+
/* TODO: output allocate size */
122+
if (max_size <= 0) {
123+
max_size = Z_STRLEN_P(data) * 3;
124+
}
125+
126+
output = (char *)emalloc(max_size+1);
127+
if (!output) {
128+
zend_error(E_WARNING, "lz4_uncompress : memory error");
129+
RETURN_FALSE;
130+
}
131+
132+
output_len = LZ4_uncompress_unknownOutputSize(Z_STRVAL_P(data), output,
133+
Z_STRLEN_P(data), max_size);
134+
135+
if (output_len <= 0) {
136+
zend_error(E_WARNING, "lz4_uncompress : data error");
137+
RETVAL_FALSE;
138+
} else {
139+
RETVAL_STRINGL(output, output_len, 1);
140+
}
141+
142+
efree(output);
143+
}

0 commit comments

Comments
 (0)