lzfse 0.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
lzfse-0.4.2/AUTHORS ADDED
@@ -0,0 +1,3 @@
1
+ Yogesh Khatri (yogesh@swiftforensics.com)
2
+ Dima Krasner (dima@dimakrasner.com)
3
+ Ofir Bibi (ofir@lightricks.com)
lzfse-0.4.2/COPYING ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2017-2020 Yogesh Khatri
2
+ Copyright (c) 2016, 2017 Dima Krasner
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2015-2016, Apple Inc. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification,
4
+ are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice,
7
+ this list of conditions and the following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+
13
+ 3. Neither the name of the copyright holder(s) nor the names of any contributors
14
+ may be used to endorse or promote products derived from this software without
15
+ specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
18
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20
+ SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22
+ TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23
+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
26
+ OF SUCH DAMAGE.
@@ -0,0 +1,10 @@
1
+ include AUTHORS
2
+ include COPYING
3
+ include LICENSE.lzfse
4
+ include *.c
5
+ include *.py
6
+ exclude .gitignore
7
+ exclude .gitmodules
8
+ exclude *.pyc
9
+ recursive-include lzfse/src *.c
10
+ recursive-include lzfse/src *.h
lzfse-0.4.2/PKG-INFO ADDED
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.1
2
+ Name: lzfse
3
+ Version: 0.4.2
4
+ Summary: Python bindings for the LZFSE reference implementation
5
+ Author-email: Yogesh Khatri <yogesh@swiftforensics.com>
6
+ Maintainer-email: m1sta <adamhamdi31@gmail.com>
7
+ License: MIT
8
+ Project-URL: Bug Tracker, https://github.com/m1stadev/lzfse/issues
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE.lzfse
12
+ License-File: COPYING
13
+ License-File: AUTHORS
14
+
15
+ <h1 align="center">
16
+ lzfse
17
+ </h1>
18
+ <p align="center">
19
+ <a href="https://github.com/m1stadev/lzfse/blob/master/LICENSE">
20
+ <image src="https://img.shields.io/github/license/m1stadev/lzfse">
21
+ </a>
22
+ <a href="https://github.com/m1stadev/lzfse">
23
+ <image src="https://tokei.rs/b1/github/m1stadev/lzfse?category=code&lang=python&style=flat">
24
+ </a>
25
+ <a href="https://github.com/m1stadev/lzfse/stargazers">
26
+ <image src="https://img.shields.io/github/stars/m1stadev/lzfse">
27
+ </a>
28
+ <br>
29
+ </p>
30
+
31
+ <p align="center">
32
+ Python bindings for the <a href="https://https://github.com/lzfse/lzfse">LZFSE</a> reference implementation.
33
+ </p>
34
+
35
+ <p align="center">
36
+ <i>This project is based on <a href="https://github.com/ydkhatri/pyliblzfse">ydkhatril's pyliblzfse</a>, I have only added CI and renamed the library to lzfse.</i>
37
+ </p>
38
+
39
+ ## Installation
40
+ - Install from [PyPI](https://pypi.org/project/lzfse/):
41
+ - ```python3 -m pip install lzfse```
42
+ - Local installation:
43
+ - `python3 -m pip install .`
lzfse-0.4.2/README.md ADDED
@@ -0,0 +1,29 @@
1
+ <h1 align="center">
2
+ lzfse
3
+ </h1>
4
+ <p align="center">
5
+ <a href="https://github.com/m1stadev/lzfse/blob/master/LICENSE">
6
+ <image src="https://img.shields.io/github/license/m1stadev/lzfse">
7
+ </a>
8
+ <a href="https://github.com/m1stadev/lzfse">
9
+ <image src="https://tokei.rs/b1/github/m1stadev/lzfse?category=code&lang=python&style=flat">
10
+ </a>
11
+ <a href="https://github.com/m1stadev/lzfse/stargazers">
12
+ <image src="https://img.shields.io/github/stars/m1stadev/lzfse">
13
+ </a>
14
+ <br>
15
+ </p>
16
+
17
+ <p align="center">
18
+ Python bindings for the <a href="https://https://github.com/lzfse/lzfse">LZFSE</a> reference implementation.
19
+ </p>
20
+
21
+ <p align="center">
22
+ <i>This project is based on <a href="https://github.com/ydkhatri/pyliblzfse">ydkhatril's pyliblzfse</a>, I have only added CI and renamed the library to lzfse.</i>
23
+ </p>
24
+
25
+ ## Installation
26
+ - Install from [PyPI](https://pypi.org/project/lzfse/):
27
+ - ```python3 -m pip install lzfse```
28
+ - Local installation:
29
+ - `python3 -m pip install .`
@@ -0,0 +1,136 @@
1
+ /*
2
+ Copyright (c) 2015-2016, Apple Inc. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
9
+ in the documentation and/or other materials provided with the distribution.
10
+
11
+ 3. Neither the name of the copyright holder(s) nor the names of any contributors may be used to endorse or promote products derived
12
+ from this software without specific prior written permission.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
16
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
19
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20
+ */
21
+
22
+ #ifndef LZFSE_H
23
+ #define LZFSE_H
24
+
25
+ #include <stddef.h>
26
+ #include <stdint.h>
27
+
28
+ #ifdef __cplusplus
29
+ extern "C" {
30
+ #endif
31
+
32
+ #if defined(_MSC_VER) && !defined(__clang__)
33
+ # define __attribute__(X)
34
+ # pragma warning(disable : 4068)
35
+ #endif
36
+
37
+ #if defined(LZFSE_DLL)
38
+ # if defined(_WIN32) || defined(__CYGWIN__)
39
+ # if defined(LZFSE_DLL_EXPORTS)
40
+ # define LZFSE_API __declspec(dllexport)
41
+ # else
42
+ # define LZFSE_API __declspec(dllimport)
43
+ # endif
44
+ # endif
45
+ #endif
46
+
47
+ #if !defined(LZFSE_API)
48
+ # if __GNUC__ >= 4
49
+ # define LZFSE_API __attribute__((visibility("default")))
50
+ # else
51
+ # define LZFSE_API
52
+ # endif
53
+ #endif
54
+
55
+ /*! @abstract Get the required scratch buffer size to compress using LZFSE. */
56
+ LZFSE_API size_t lzfse_encode_scratch_size();
57
+
58
+ /*! @abstract Compress a buffer using LZFSE.
59
+ *
60
+ * @param dst_buffer
61
+ * Pointer to the first byte of the destination buffer.
62
+ *
63
+ * @param dst_size
64
+ * Size of the destination buffer in bytes.
65
+ *
66
+ * @param src_buffer
67
+ * Pointer to the first byte of the source buffer.
68
+ *
69
+ * @param src_size
70
+ * Size of the source buffer in bytes.
71
+ *
72
+ * @param scratch_buffer
73
+ * If non-NULL, a pointer to scratch space for the routine to use as workspace;
74
+ * the routine may use up to lzfse_encode_scratch_size( ) bytes of workspace
75
+ * during its operation, and will not perform any internal allocations. If
76
+ * NULL, the routine may allocate its own memory to use during operation via
77
+ * a single call to malloc( ), and will release it by calling free( ) prior
78
+ * to returning. For most use, passing NULL is perfectly satisfactory, but if
79
+ * you require strict control over allocation, you will want to pass an
80
+ * explicit scratch buffer.
81
+ *
82
+ * @return
83
+ * The number of bytes written to the destination buffer if the input is
84
+ * successfully compressed. If the input cannot be compressed to fit into
85
+ * the provided buffer, or an error occurs, zero is returned, and the
86
+ * contents of dst_buffer are unspecified. */
87
+ LZFSE_API size_t lzfse_encode_buffer(uint8_t *__restrict dst_buffer,
88
+ size_t dst_size,
89
+ const uint8_t *__restrict src_buffer,
90
+ size_t src_size,
91
+ void *__restrict scratch_buffer);
92
+
93
+ /*! @abstract Get the required scratch buffer size to decompress using LZFSE. */
94
+ LZFSE_API size_t lzfse_decode_scratch_size();
95
+
96
+ /*! @abstract Decompress a buffer using LZFSE.
97
+ *
98
+ * @param dst_buffer
99
+ * Pointer to the first byte of the destination buffer.
100
+ *
101
+ * @param dst_size
102
+ * Size of the destination buffer in bytes.
103
+ *
104
+ * @param src_buffer
105
+ * Pointer to the first byte of the source buffer.
106
+ *
107
+ * @param src_size
108
+ * Size of the source buffer in bytes.
109
+ *
110
+ * @param scratch_buffer
111
+ * If non-NULL, a pointer to scratch space for the routine to use as workspace;
112
+ * the routine may use up to lzfse_decode_scratch_size( ) bytes of workspace
113
+ * during its operation, and will not perform any internal allocations. If
114
+ * NULL, the routine may allocate its own memory to use during operation via
115
+ * a single call to malloc( ), and will release it by calling free( ) prior
116
+ * to returning. For most use, passing NULL is perfectly satisfactory, but if
117
+ * you require strict control over allocation, you will want to pass an
118
+ * explicit scratch buffer.
119
+ *
120
+ * @return
121
+ * The number of bytes written to the destination buffer if the input is
122
+ * successfully decompressed. If there is not enough space in the destination
123
+ * buffer to hold the entire expanded output, only the first dst_size bytes
124
+ * will be written to the buffer and dst_size is returned. Note that this
125
+ * behavior differs from that of lzfse_encode_buffer. */
126
+ LZFSE_API size_t lzfse_decode_buffer(uint8_t *__restrict dst_buffer,
127
+ size_t dst_size,
128
+ const uint8_t *__restrict src_buffer,
129
+ size_t src_size,
130
+ void *__restrict scratch_buffer);
131
+
132
+ #ifdef __cplusplus
133
+ } /* extern "C" */
134
+ #endif
135
+
136
+ #endif /* LZFSE_H */
@@ -0,0 +1,72 @@
1
+ /*
2
+ Copyright (c) 2015-2016, Apple Inc. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
9
+ in the documentation and/or other materials provided with the distribution.
10
+
11
+ 3. Neither the name of the copyright holder(s) nor the names of any contributors may be used to endorse or promote products derived
12
+ from this software without specific prior written permission.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
16
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
19
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20
+ */
21
+
22
+ // LZFSE decode API
23
+
24
+ #include "lzfse.h"
25
+ #include "lzfse_internal.h"
26
+
27
+ size_t lzfse_decode_scratch_size() { return sizeof(lzfse_decoder_state); }
28
+
29
+ size_t lzfse_decode_buffer_with_scratch(uint8_t *__restrict dst_buffer,
30
+ size_t dst_size, const uint8_t *__restrict src_buffer,
31
+ size_t src_size, void *__restrict scratch_buffer) {
32
+ lzfse_decoder_state *s = (lzfse_decoder_state *)scratch_buffer;
33
+ memset(s, 0x00, sizeof(*s));
34
+
35
+ // Initialize state
36
+ s->src = src_buffer;
37
+ s->src_begin = src_buffer;
38
+ s->src_end = s->src + src_size;
39
+ s->dst = dst_buffer;
40
+ s->dst_begin = dst_buffer;
41
+ s->dst_end = dst_buffer + dst_size;
42
+
43
+ // Decode
44
+ int status = lzfse_decode(s);
45
+ if (status == LZFSE_STATUS_DST_FULL)
46
+ return dst_size;
47
+ if (status != LZFSE_STATUS_OK)
48
+ return 0; // failed
49
+ return (size_t)(s->dst - dst_buffer); // bytes written
50
+ }
51
+
52
+ size_t lzfse_decode_buffer(uint8_t *__restrict dst_buffer, size_t dst_size,
53
+ const uint8_t *__restrict src_buffer,
54
+ size_t src_size, void *__restrict scratch_buffer) {
55
+ int has_malloc = 0;
56
+ size_t ret = 0;
57
+
58
+ // Deal with the possible NULL pointer
59
+ if (scratch_buffer == NULL) {
60
+ // +1 in case scratch size could be zero
61
+ scratch_buffer = malloc(lzfse_decode_scratch_size() + 1);
62
+ has_malloc = 1;
63
+ }
64
+ if (scratch_buffer == NULL)
65
+ return 0;
66
+ ret = lzfse_decode_buffer_with_scratch(dst_buffer,
67
+ dst_size, src_buffer,
68
+ src_size, scratch_buffer);
69
+ if (has_malloc)
70
+ free(scratch_buffer);
71
+ return ret;
72
+ }