forked from MDSplus/mdsplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gzipcompress.c
86 lines (73 loc) · 1.84 KB
/
gzipcompress.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <string.h>
#include <mdsdescrip.h>
#include <strroutines.h>
#include <stdio.h>
#include <stdarg.h>
#include <zlib.h>
//#define DEBUG
#define UNUSED(x) (void)(x)
EXPORT int gzip(
const int *const nitems_ptr,
const mdsdsc_a_t *const items_dsc_ptr,
mdsdsc_a_t *const pack_dsc_ptr,
int *const bit_ptr,
mdsdsc_d_t * const pdximage,
mdsdsc_d_t * const pdxentry
)
{
int ret;
UNUSED(nitems_ptr);
// unsigned long maxDestinationSize = compressBound(items_dsc_ptr->length);
unsigned long pack_length = pack_dsc_ptr->arsize;
static const DESCRIPTOR(image, "libMdsShr");
static const DESCRIPTOR(routine, "gunzip");
ret = compress(
(Bytef *)pack_dsc_ptr->pointer,
&pack_length,
(Bytef *)items_dsc_ptr->pointer,
items_dsc_ptr->arsize
);
if (ret != Z_OK) {
return LibSTRTRU;
}
#ifdef DEBUG
printf("gzip() %u => %lu\n", pack_dsc_ptr->arsize, pack_length);
#endif
// The new compressed length, in bits (for some reason)
*bit_ptr = pack_length * 8;
if (pdximage) {
StrCopyDx((mdsdsc_t * const)pdximage, &image);
}
if (pdxentry) {
StrCopyDx((mdsdsc_t * const)pdxentry, &routine);
}
#ifdef DEBUG
printf("gzip() called successfully\n");
#endif
return 1;
}
EXPORT int gunzip(
int *const nitems_ptr,
const mdsdsc_a_t *const pack_dsc_ptr,
mdsdsc_a_t *const items_dsc_ptr,
int *const bit_ptr
)
{
int ret;
UNUSED(nitems_ptr);
UNUSED(bit_ptr);
unsigned long items_length = items_dsc_ptr->arsize;
ret = uncompress(
(Bytef *)items_dsc_ptr->pointer,
&items_length,
(Bytef *)pack_dsc_ptr->pointer,
pack_dsc_ptr->arsize
);
if (ret != Z_OK) {
return LibINVSTRDES;
}
#ifdef DEBUG
printf("gunzip() called successfully\n");
#endif
return 1;
}