Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
shrapnel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
shrapnel
Commits
c034f9cb
Commit
c034f9cb
authored
Dec 20, 2011
by
Sam Rushing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zstack object implemented with zlib
parent
214f41e8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
0 deletions
+55
-0
coro/zstack_zlib.pyx
coro/zstack_zlib.pyx
+55
-0
No files found.
coro/zstack_zlib.pyx
0 → 100644
View file @
c034f9cb
# -*- Mode: Cython -*-
class
ZlibError
(
Exception
):
"A problem with zlib"
cimport
zlib
cdef
class
zstack
:
cdef
zlib
.
z_stream
squish
,
unsquish
# this buffer is only used for compression
cdef
unsigned
char
*
buffer
cdef
int
buffer_size
def
__init__
(
self
,
int
size
=
4
*
1024
*
1024
):
cdef
int
r
self
.
squish
.
zalloc
=
NULL
self
.
squish
.
zfree
=
NULL
self
.
squish
.
opaque
=
NULL
self
.
unsquish
.
zalloc
=
NULL
self
.
unsquish
.
zfree
=
NULL
self
.
unsquish
.
opaque
=
NULL
self
.
buffer
=
<
unsigned
char
*>
PyMem_Malloc
(
size
)
if
not
self
.
buffer
:
raise
MemoryError
self
.
buffer_size
=
size
r
=
zlib
.
deflateInit
(
&
self
.
squish
,
zlib
.
Z_BEST_SPEED
)
if
r
!=
zlib
.
Z_OK
:
raise
ZlibError
(
r
)
r
=
zlib
.
inflateInit
(
&
self
.
unsquish
)
if
r
!=
zlib
.
Z_OK
:
raise
ZlibError
(
r
)
def
__dealloc__
(
self
):
zlib
.
deflateEnd
(
&
self
.
squish
)
zlib
.
inflateEnd
(
&
self
.
unsquish
)
PyMem_Free
(
self
.
buffer
)
cdef
size_t
deflate
(
self
,
void
*
base
,
size_t
size
):
zlib
.
deflateReset
(
&
self
.
squish
)
self
.
squish
.
next_in
=
<
unsigned
char
*>
base
self
.
squish
.
avail_in
=
size
self
.
squish
.
next_out
=
self
.
buffer
self
.
squish
.
avail_out
=
self
.
buffer_size
zlib
.
deflate
(
&
self
.
squish
,
1
)
# return the compressed size
return
self
.
buffer_size
-
self
.
squish
.
avail_out
cdef
size_t
inflate
(
self
,
void
*
dst
,
size_t
dsize
,
void
*
src
,
size_t
ssize
):
zlib
.
inflateReset
(
&
self
.
unsquish
)
self
.
unsquish
.
next_in
=
<
unsigned
char
*>
src
self
.
unsquish
.
avail_in
=
ssize
self
.
unsquish
.
next_out
=
<
unsigned
char
*>
dst
self
.
unsquish
.
avail_out
=
dsize
zlib
.
inflate
(
&
self
.
unsquish
,
1
)
# return the uncompressed size
return
dsize
-
self
.
unsquish
.
avail_out
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment