2014-12-29 20:34:41 +00:00
|
|
|
/*
|
2015-09-05 17:22:52 +00:00
|
|
|
* Bled (Base Library for Easy Decompression)
|
2014-12-29 20:34:41 +00:00
|
|
|
*
|
2015-01-01 23:39:28 +00:00
|
|
|
* Copyright © 2014-2015 Pete Batard <pete@akeo.ie>
|
2014-12-29 20:34:41 +00:00
|
|
|
*
|
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef ARRAYSIZE
|
2015-01-01 23:39:28 +00:00
|
|
|
#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
|
2014-12-29 20:34:41 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef void (*printf_t) (const char* format, ...);
|
2015-01-01 23:39:28 +00:00
|
|
|
typedef void (*progress_t) (const uint64_t read_bytes);
|
2019-12-26 23:19:48 +00:00
|
|
|
typedef int (*read_t)(int fd, void* buf, unsigned int count);
|
|
|
|
typedef int (*write_t)(int fd, const void* buf, unsigned int count);
|
2014-12-29 20:34:41 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
BLED_COMPRESSION_NONE = 0,
|
|
|
|
BLED_COMPRESSION_ZIP, // .zip
|
|
|
|
BLED_COMPRESSION_LZW, // .Z
|
|
|
|
BLED_COMPRESSION_GZIP, // .gz
|
|
|
|
BLED_COMPRESSION_LZMA, // .lzma
|
|
|
|
BLED_COMPRESSION_BZIP2, // .bz2
|
|
|
|
BLED_COMPRESSION_XZ, // .xz
|
2015-02-11 23:22:18 +00:00
|
|
|
BLED_COMPRESSION_7ZIP, // .7z
|
2014-12-29 20:34:41 +00:00
|
|
|
BLED_COMPRESSION_MAX
|
|
|
|
} bled_compression_type;
|
|
|
|
|
|
|
|
/* Uncompress file 'src', compressed using 'type', to file 'dst' */
|
|
|
|
int64_t bled_uncompress(const char* src, const char* dst, int type);
|
|
|
|
|
2015-01-01 23:39:28 +00:00
|
|
|
/* Uncompress using Windows handles */
|
2014-12-29 20:34:41 +00:00
|
|
|
int64_t bled_uncompress_with_handles(HANDLE hSrc, HANDLE hDst, int type);
|
|
|
|
|
2015-02-11 23:22:18 +00:00
|
|
|
/* Uncompress file 'src', compressed using 'type', to buffer 'buf' of size 'size' */
|
|
|
|
int64_t bled_uncompress_to_buffer(const char* src, char* buf, size_t size, int type);
|
|
|
|
|
2019-03-23 13:59:20 +00:00
|
|
|
/* Uncompress buffer 'src' of length 'src_len' to buffer 'dst' of size 'dst_len' */
|
|
|
|
int64_t bled_uncompress_from_buffer_to_buffer(const char* src, const size_t src_len, char* dst, size_t dst_len, int type);
|
|
|
|
|
2015-01-01 23:39:28 +00:00
|
|
|
/* Initialize the library.
|
|
|
|
* When the parameters are not NULL you can:
|
|
|
|
* - specify the printf-like function you want to use to output message
|
|
|
|
* void print_function(const char* format, ...);
|
2019-12-26 23:19:48 +00:00
|
|
|
* - specify the read/write functions you want to use;
|
2015-01-01 23:39:28 +00:00
|
|
|
* - specify the function you want to use to display progress, based on number of source archive bytes read
|
|
|
|
* void progress_function(const uint64_t read_bytes);
|
|
|
|
* - point to an unsigned long variable, to be used to cancel operations when set to non zero
|
|
|
|
*/
|
2019-12-26 23:19:48 +00:00
|
|
|
int bled_init(printf_t print_function, read_t read_function, write_t write_function,
|
|
|
|
progress_t progress_function, unsigned long* cancel_request);
|
2014-12-29 20:34:41 +00:00
|
|
|
|
2015-01-01 23:39:28 +00:00
|
|
|
/* This call frees any resource used by the library */
|
2014-12-29 20:34:41 +00:00
|
|
|
void bled_exit(void);
|