Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
b3d5ee14
Commit
b3d5ee14
authored
18 years ago
by
Martin Nilsson
Browse files
Options
Downloads
Patches
Plain Diff
pack() allows for Gz compresion without creating an object.
Rev: src/modules/Gz/zlibmod.c:1.73
parent
7df7b602
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/modules/Gz/zlibmod.c
+100
-3
100 additions, 3 deletions
src/modules/Gz/zlibmod.c
with
100 additions
and
3 deletions
src/modules/Gz/zlibmod.c
+
100
−
3
View file @
b3d5ee14
...
...
@@ -2,7 +2,7 @@
|| This file is part of Pike. For copyright information see COPYRIGHT.
|| Pike is distributed under GPL, LGPL and MPL. See the file COPYING
|| for more information.
|| $Id: zlibmod.c,v 1.7
2
2006/0
7/26 18:02:30
nilsson Exp $
|| $Id: zlibmod.c,v 1.7
3
2006/0
8/02 16:19:08
nilsson Exp $
*/
#include
"global.h"
...
...
@@ -174,6 +174,7 @@ static void gz_deflate_create(INT32 args)
}
}
static
int
do_deflate
(
dynamic_buffer
*
buf
,
struct
zipper
*
this
,
int
flush
)
...
...
@@ -211,6 +212,99 @@ static int do_deflate(dynamic_buffer *buf,
return
ret
;
}
static
void
free_pack
(
struct
zipper
*
z
)
{
deflateEnd
(
&
z
->
gz
);
mt_destroy
(
&
z
->
lock
);
toss_buffer
((
dynamic_buffer
*
)
z
->
gz
.
opaque
);
}
static
void
pack
(
struct
pike_string
*
data
,
dynamic_buffer
*
buf
,
int
level
,
int
strategy
,
int
wbits
)
{
struct
zipper
z
;
ONERROR
err
;
int
ret
;
if
(
level
<
Z_NO_COMPRESSION
||
level
>
Z_BEST_COMPRESSION
)
Pike_error
(
"Compression level out of range for pack. %d %d %d
\n
"
,
Z_DEFAULT_COMPRESSION
,
Z_NO_COMPRESSION
,
Z_BEST_COMPRESSION
);
if
(
strategy
!=
Z_DEFAULT_STRATEGY
&&
strategy
!=
Z_FILTERED
&&
#ifdef Z_RLE
strategy
!=
Z_RLE
&&
#endif
#ifdef Z_FIXED
strategy
!=
Z_FIXED
&&
#endif
strategy
!=
Z_HUFFMAN_ONLY
)
Pike_error
(
"Invalid compression strategy %d for pack.
\n
"
,
strategy
);
if
(
wbits
!=
15
&&
wbits
!=-
15
)
Pike_error
(
"Invalid wbits value %d for pack.
\n
"
,
wbits
);
MEMSET
(
&
z
,
0
,
sizeof
(
z
));
z
.
gz
.
zalloc
=
Z_NULL
;
z
.
gz
.
zfree
=
Z_NULL
;
ret
=
deflateInit2
(
&
z
.
gz
,
level
,
Z_DEFLATED
,
wbits
,
9
,
strategy
);
switch
(
ret
)
{
case
Z_OK
:
break
;
case
Z_VERSION_ERROR
:
Pike_error
(
"libz not compatible with zlib.h!!!
\n
"
);
break
;
default:
if
(
THIS
->
gz
.
msg
)
Pike_error
(
"Failed to initialize gz: %s
\n
"
,
THIS
->
gz
.
msg
);
else
Pike_error
(
"Failed to initialize gz
\n
"
);
}
z
.
gz
.
next_in
=
(
Bytef
*
)
data
->
str
;
z
.
gz
.
avail_in
=
(
unsigned
INT32
)(
data
->
len
);
initialize_buf
(
buf
);
z
.
gz
.
opaque
=
buf
;
mt_init
(
&
z
.
lock
);
SET_ONERROR
(
err
,
free_pack
,
&
z
);
ret
=
do_deflate
(
buf
,
&
z
,
Z_FINISH
);
UNSET_ONERROR
(
err
);
deflateEnd
(
&
z
.
gz
);
mt_destroy
(
&
z
.
lock
);
}
/* @decl string pack(string data, void|int(0..1) raw, void|int level,@
* void|int strategy)
*/
static
void
gz_pack
(
INT32
args
)
{
struct
pike_string
*
data
;
dynamic_buffer
buf
;
int
wbits
=
15
;
int
raw
=
0
;
int
level
=
8
;
int
strategy
=
Z_DEFAULT_STRATEGY
;
get_all_args
(
"pack"
,
args
,
"%n.%d%d%d"
,
&
data
,
&
raw
,
&
level
,
&
strategy
);
if
(
raw
)
wbits
=
-
wbits
;
pack
(
data
,
&
buf
,
level
,
strategy
,
wbits
);
pop_n_elems
(
args
);
push_string
(
low_free_buf
(
&
buf
));
}
/*! @decl string deflate(string data, int|void flush)
*!
*! This function performs gzip style compression on a string @[data] and
...
...
@@ -694,10 +788,13 @@ PIKE_MODULE_INIT
#endif
/* function(string,void|int:int) */
ADD_FUNCTION
(
"crc32"
,
gz_crc32
,
tFunc
(
tStr
tOr
(
tVoid
,
tInt
),
tInt
),
OPT_TRY_OPTIMIZE
);
ADD_FUNCTION
(
"crc32"
,
gz_crc32
,
tFunc
(
tStr
tOr
(
tVoid
,
tInt
),
tInt
),
0
);
/* function(string,void|int(0..1),void|int,void|int:string) */
ADD_FUNCTION
(
"pack"
,
gz_pack
,
tFunc
(
tStr
tOr
(
tVoid
,
tInt01
)
tOr
(
tVoid
,
tInt
)
tOr
(
tVoid
,
tInt
),
tStr
),
0
);
PIKE_MODULE_EXPORT
(
Gz
,
crc32
);
PIKE_MODULE_EXPORT
(
Gz
,
pack
);
#else
if
(
!
TEST_COMPAT
(
7
,
6
))
HIDE_MODULE
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment