Squash
0.7.0
|
stdio-like API and utilities More...
Functions | |
SquashFile * | squash_file_open (const char *codec, const char *filename, const char *mode,...) |
Open a file. More... | |
SquashFile * | squash_file_open_codec (SquashCodec *codec, const char *filename, const char *mode,...) |
Open a file using a codec instance. More... | |
SquashFile * | squash_file_open_with_options (const char *codec, const char *filename, const char *mode, SquashOptions *options) |
Open a file with the specified options. More... | |
SquashFile * | squash_file_open_codec_with_options (SquashCodec *codec, const char *filename, const char *mode, SquashOptions *options) |
Open a file using a codec instance with the specified options. More... | |
SquashFile * | squash_file_steal (const char *codec, FILE *fp,...) |
Open an existing stdio file. More... | |
SquashFile * | squash_file_steal_codec (SquashCodec *codec, FILE *fp,...) |
Open an existing stdio file using a codec instance. More... | |
SquashFile * | squash_file_steal_with_options (const char *codec, FILE *fp, SquashOptions *options) |
Open an existing stdio file with the specified options. More... | |
SquashFile * | squash_file_steal_codec_with_options (SquashCodec *codec, FILE *fp, SquashOptions *options) |
Open an existing stdio file using a codec instance with the specified options. More... | |
SquashStatus | squash_file_read (SquashFile *file, size_t *decompressed_length, uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)]) |
Read from a compressed file. More... | |
SquashStatus | squash_file_write (SquashFile *file, size_t uncompressed_length, const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)]) |
Write data to a compressed file. More... | |
SquashStatus | squash_file_flush (SquashFile *file) |
immediately write any buffered data to a file More... | |
bool | squash_file_eof (SquashFile *file) |
Determine whether the file has reached the end of file. More... | |
SquashStatus | squash_splice (const char *codec, SquashStreamType stream_type, FILE *fp_out, FILE *fp_in, size_t length,...) |
compress or decompress the contents of one file to another More... | |
SquashStatus | squash_splice_codec (SquashCodec *codec, SquashStreamType stream_type, FILE *fp_out, FILE *fp_in, size_t length,...) |
compress or decompress the contents of one file to another More... | |
SquashStatus | squash_splice_with_options (const char *codec, SquashStreamType stream_type, FILE *fp_out, FILE *fp_in, size_t length, SquashOptions *options) |
compress or decompress the contents of one file to another More... | |
SquashStatus | squash_splice_codec_with_options (SquashCodec *codec, SquashStreamType stream_type, FILE *fp_out, FILE *fp_in, size_t length, SquashOptions *options) |
compress or decompress the contents of one file to another More... | |
SquashStatus | squash_file_close (SquashFile *file) |
Close a file. More... | |
SquashStatus | squash_file_free (SquashFile *file, FILE **fp) |
Free a file. More... | |
stdio-like API and utilities
These functions provide an API which should be familiar for those used to dealing with the standard I/O functions.
Additionally, a splice function family is provided which is inspired by the Linux-specific splice(2) function.
SquashStatus squash_file_close | ( | SquashFile * | file | ) |
Close a file.
If file is a compressor the stream will finish compressing, writing any buffered data. For codecs which do not provide a native streaming interface, all of the actual compression will take place during this call. In other words, it may block for a non-trivial period. If this is a problem please file a bug against Squash (including your use case), and we can discuss adding a function call which will simply abort compression.
In addition to freeing the SquashFile instance, this function will close the underlying FILE pointer. If you wish to continue using the FILE for something else, use squash_file_free instead.
file | file to close |
bool squash_file_eof | ( | SquashFile * | file | ) |
SquashStatus squash_file_flush | ( | SquashFile * | file | ) |
immediately write any buffered data to a file
file | file to flush |
SquashStatus squash_file_free | ( | SquashFile * | file, |
FILE ** | fp | ||
) |
Free a file.
This function will free the SquashFile, but unlike squash_file_close it will not actually close the underlying FILE
pointer. Instead, it will return the value in the fp argument, allowing you to further manipulate it.
file | file to free | |
[out] | fp | location to store the underlying FILE pointer |
SquashFile* squash_file_open | ( | const char * | codec, |
const char * | filename, | ||
const char * | mode, | ||
... | |||
) |
Open a file.
The mode parameter will be passed through to fopen, so the value must valid. Note that Squash may attempt to use mmap regardless of whether the m flag is passed.
The file is always assumed to be compressed—calling squash_file_write will always compress, and calling squash_file_read will always decompress. Note, however, that you cannot mix reading and writing to the same file as you can with a standard FILE.
filename | name of the file to open |
mode | file mode |
codec | codec to use |
... | options |
SquashFile* squash_file_open_codec | ( | SquashCodec * | codec, |
const char * | filename, | ||
const char * | mode, | ||
... | |||
) |
Open a file using a codec instance.
filename | name of the file to open |
mode | file mode |
codec | codec to use |
... | options |
SquashFile* squash_file_open_codec_with_options | ( | SquashCodec * | codec, |
const char * | filename, | ||
const char * | mode, | ||
SquashOptions * | options | ||
) |
Open a file using a codec instance with the specified options.
filename | name of the file to open |
mode | file mode |
codec | codec to use |
options | options |
SquashFile* squash_file_open_with_options | ( | const char * | codec, |
const char * | filename, | ||
const char * | mode, | ||
SquashOptions * | options | ||
) |
Open a file with the specified options.
filename | name of the file to open |
mode | file mode |
codec | codec to use |
options | options |
SquashStatus squash_file_read | ( | SquashFile * | file, |
size_t * | decompressed_length, | ||
uint8_t | decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)] | ||
) |
Read from a compressed file.
Attempt to read decompressed_length bytes of decompressed data into the decompressed buffer. The number of bytes of compressed data read from the input file may be significantly more, or less, than decompressed_length.
The number of decompressed bytes successfully read from the file will be stored in decompressed_read after this function is execute. This value will never be greater than decompressed_length, but it may be less if there was an error or the end of the input file was reached.
file | the file to read from |
decompressed_length | number of bytes to attempt to write to decompressed |
decompressed | buffer to write the decompressed data to |
SQUASH_OK | successfully read some data |
SQUASH_END_OF_STREAM | the end of the file was reached |
SquashFile* squash_file_steal | ( | const char * | codec, |
FILE * | fp, | ||
... | |||
) |
Open an existing stdio file.
fp | the stdio file to use |
codec | codec to use |
... | options |
SquashFile* squash_file_steal_codec | ( | SquashCodec * | codec, |
FILE * | fp, | ||
... | |||
) |
Open an existing stdio file using a codec instance.
fp | the stdio file to use |
codec | codec to use |
... | options |
SquashFile* squash_file_steal_codec_with_options | ( | SquashCodec * | codec, |
FILE * | fp, | ||
SquashOptions * | options | ||
) |
Open an existing stdio file using a codec instance with the specified options.
fp | the stdio file to use |
codec | codec to use |
options | options |
SquashFile* squash_file_steal_with_options | ( | const char * | codec, |
FILE * | fp, | ||
SquashOptions * | options | ||
) |
Open an existing stdio file with the specified options.
fp | the stdio file to use |
codec | codec to use |
options | options |
SquashStatus squash_file_write | ( | SquashFile * | file, |
size_t | uncompressed_length, | ||
const uint8_t | uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)] | ||
) |
Write data to a compressed file.
Attempt to write the compressed equivalent of uncompressed to a file. The number of bytes of compressed data written to the output file may be significantly more, or less, than the uncompressed_length.
file | file to write to |
uncompressed_length | number of bytes of uncompressed data in uncompressed to attempt to write |
uncompressed | data to write |
SquashStatus squash_splice | ( | const char * | codec, |
SquashStreamType | stream_type, | ||
FILE * | fp_out, | ||
FILE * | fp_in, | ||
size_t | length, | ||
... | |||
) |
compress or decompress the contents of one file to another
This function will attempt to compress or decompress the contents of one file to another. It will attempt to use memory-mapped files in order to reduce memory usage and increase performance, and so should be preferred over writing similar code manually.
fp_in | the input FILE pointer |
fp_out | the output FILE pointer |
length | number of bytes (uncompressed) to transfer from fp_in to fp_out, or 0 to transfer the entire file |
stream_type | whether to compress or decompress the data |
codec | the name of the codec to use |
... | list of options (with a NULL sentinel) |
SquashStatus squash_splice_codec | ( | SquashCodec * | codec, |
SquashStreamType | stream_type, | ||
FILE * | fp_out, | ||
FILE * | fp_in, | ||
size_t | length, | ||
... | |||
) |
compress or decompress the contents of one file to another
This function will attempt to compress or decompress the contents of one file to another. It will attempt to use memory-mapped files in order to reduce memory usage and increase performance, and so should be preferred over writing similar code manually.
fp_in | the input FILE pointer |
fp_out | the output FILE pointer |
length | number of bytes (uncompressed) to transfer from fp_in to fp_out |
stream_type | whether to compress or decompress the data |
codec | codec to use |
... | list of options (with a NULL sentinel) |
SquashStatus squash_splice_codec_with_options | ( | SquashCodec * | codec, |
SquashStreamType | stream_type, | ||
FILE * | fp_out, | ||
FILE * | fp_in, | ||
size_t | length, | ||
SquashOptions * | options | ||
) |
compress or decompress the contents of one file to another
This function will attempt to compress or decompress the contents of one file to another. It will attempt to use memory-mapped files in order to reduce memory usage and increase performance, and so should be preferred over writing similar code manually.
fp_in | the input FILE pointer |
fp_out | the output FILE pointer |
length | number of bytes (uncompressed) to transfer from fp_in to fp_out |
stream_type | whether to compress or decompress the data |
codec | codec to use |
options | options to pass to the codec |
SquashStatus squash_splice_with_options | ( | const char * | codec, |
SquashStreamType | stream_type, | ||
FILE * | fp_out, | ||
FILE * | fp_in, | ||
size_t | length, | ||
SquashOptions * | options | ||
) |
compress or decompress the contents of one file to another
This function will attempt to compress or decompress the contents of one file to another. It will attempt to use memory-mapped files in order to reduce memory usage and increase performance, and so should be preferred over writing similar code manually.
fp_in | the input FILE pointer |
fp_out | the output FILE pointer |
length | number of bytes (uncompressed) to transfer from fp_in to fp_out |
stream_type | whether to compress or decompress the data |
codec | name of the codec to use |
options | options to pass to the codec |