Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
file_compressed.h
1/* file_compressed.h
2 * Declarations for writing compressed files.
3 *
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <[email protected]>
6 * Copyright 1998 Gerald Combs
7 *
8 * Derived from code in the Wiretap Library
9 * Copyright (c) 1998 by Gilbert Ramirez <[email protected]>
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 */
13
14#ifndef __WSUTIL_FILE_COMPRESSED_H__
15#define __WSUTIL_FILE_COMPRESSED_H__
16
17#ifdef __cplusplus
18extern "C" {
19#endif /* __cplusplus */
20
21/*
22 * Types of compression for a file, including "none".
23 */
24typedef enum {
25 WS_FILE_UNCOMPRESSED,
26 WS_FILE_GZIP_COMPRESSED,
27 WS_FILE_ZSTD_COMPRESSED,
28 WS_FILE_LZ4_COMPRESSED,
29 WS_FILE_UNKNOWN_COMPRESSION,
30} ws_compression_type;
31
32WS_DLL_PUBLIC ws_compression_type
33ws_name_to_compression_type(const char *name);
34
35WS_DLL_PUBLIC ws_compression_type
36ws_extension_to_compression_type(const char *ext);
37
38WS_DLL_PUBLIC bool
39ws_can_write_compression_type(ws_compression_type compression_type);
40
41WS_DLL_PUBLIC const char *
42ws_compression_type_description(ws_compression_type compression_type);
43
44WS_DLL_PUBLIC const char *
45ws_compression_type_extension(ws_compression_type compression_type);
46
47WS_DLL_PUBLIC const char *
48ws_compression_type_name(ws_compression_type compression_type);
49
50WS_DLL_PUBLIC GSList *
51ws_get_all_compression_type_extensions_list(void);
52
53WS_DLL_PUBLIC GSList *
54ws_get_all_output_compression_type_names_list(void);
55
56/*
57 * (Possibly) compressed writable stream.
58 * Data is written to the stream using one of the above compression
59 * types, if the type supports writing.
60 *
61 * One of those types is WS_FILE_UNCOMPRESSED, which is why it's
62 * *possibly* compressed.
63 */
64typedef struct ws_cwstream ws_cwstream;
65
66WS_DLL_PUBLIC ws_cwstream*
67ws_cwstream_open(const char *filename, ws_compression_type ctype, int *err);
68
69WS_DLL_PUBLIC ws_cwstream*
70ws_cwstream_fdopen(int fd, ws_compression_type ctype, int *err);
71
72WS_DLL_PUBLIC ws_cwstream*
73ws_cwstream_open_stdout(ws_compression_type ctype, int *err);
74
75/* Write to file */
76WS_DLL_PUBLIC bool
77ws_cwstream_write(ws_cwstream* pfile, const uint8_t* data, size_t data_length,
78 uint64_t *bytes_written, int *err);
79
80WS_DLL_PUBLIC bool
81ws_cwstream_flush(ws_cwstream* pfile, int *err);
82
83/* Close open file handles and frees memory associated with pfile.
84 *
85 * Return true on success, returns false and sets err (optional) on failure.
86 * err can be NULL, e.g. if closing after some other failure that is more
87 * relevant to report, or when exiting a program. */
88WS_DLL_PUBLIC bool
89ws_cwstream_close(ws_cwstream* pfile, int *err);
90
91#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG)
92
93typedef struct gzip_writer *GZWFILE_T;
94
95WS_DLL_PUBLIC GZWFILE_T gzwfile_open(const char *path);
96WS_DLL_PUBLIC GZWFILE_T gzwfile_fdopen(int fd);
97WS_DLL_PUBLIC unsigned gzwfile_write(GZWFILE_T state, const void *buf, unsigned len);
98WS_DLL_PUBLIC int gzwfile_flush(GZWFILE_T state);
99WS_DLL_PUBLIC int gzwfile_close(GZWFILE_T state);
100WS_DLL_PUBLIC int gzwfile_geterr(GZWFILE_T state);
101#endif /* HAVE_ZLIB */
102
103#ifdef HAVE_LZ4
104typedef struct lz4_writer *LZ4WFILE_T;
105
106WS_DLL_PUBLIC LZ4WFILE_T lz4wfile_open(const char *path);
107WS_DLL_PUBLIC LZ4WFILE_T lz4wfile_fdopen(int fd);
108WS_DLL_PUBLIC size_t lz4wfile_write(LZ4WFILE_T state, const void *buf, size_t len);
109WS_DLL_PUBLIC int lz4wfile_flush(LZ4WFILE_T state);
110WS_DLL_PUBLIC int lz4wfile_close(LZ4WFILE_T state);
111WS_DLL_PUBLIC int lz4wfile_geterr(LZ4WFILE_T state);
112#endif
113
114#ifdef __cplusplus
115}
116#endif /* __cplusplus */
117
118#endif /* __WSUTIL_FILE_COMPRESSED_H__ */
Definition file_compressed.c:159