Skip to content

Commit

Permalink
[cmp] add ztsd image compression support
Browse files Browse the repository at this point in the history
* Based on the latest Bled, which adds ztsd compression support.
* Note that initial extraction of the 512 bytes MBR is very slow, because is seems
  clear that ZSTD was never designed for fast init or processing small elements of
  data, but instead for post init large volume streaming.
* Also note that this code adds 400 KB to the Rufus executable *AFTER UPX COMPRESSION*!
  Hopefully, the BusyBox folks can come up with a better and smaller way to add zstd
  support, because it's clear that the method used by the current BusyBox proposal,
  which is to leave as much of the original code untouched, isn't for the best...
* Closes #2590.
* Closes #2620.
* Closes #2621.
  • Loading branch information
pbatard committed Nov 22, 2024
1 parent fcdde3d commit cef7a5c
Show file tree
Hide file tree
Showing 38 changed files with 10,440 additions and 22 deletions.
24 changes: 24 additions & 0 deletions .vs/bled.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,56 @@
<ClCompile Include="..\src\bled\decompress_unlzma.c" />
<ClCompile Include="..\src\bled\decompress_unxz.c" />
<ClCompile Include="..\src\bled\decompress_unzip.c" />
<ClCompile Include="..\src\bled\decompress_unzstd.c" />
<ClCompile Include="..\src\bled\decompress_vtsi.c" />
<ClCompile Include="..\src\bled\filter_accept_all.c" />
<ClCompile Include="..\src\bled\filter_accept_list.c" />
<ClCompile Include="..\src\bled\filter_accept_reject_list.c" />
<ClCompile Include="..\src\bled\find_list_entry.c" />
<ClCompile Include="..\src\bled\fse_decompress.c" />
<ClCompile Include="..\src\bled\header_list.c" />
<ClCompile Include="..\src\bled\header_skip.c" />
<ClCompile Include="..\src\bled\header_verbose_list.c" />
<ClCompile Include="..\src\bled\huf_decompress.c" />
<ClCompile Include="..\src\bled\init_handle.c" />
<ClCompile Include="..\src\bled\open_transformer.c" />
<ClCompile Include="..\src\bled\seek_by_jump.c" />
<ClCompile Include="..\src\bled\seek_by_read.c" />
<ClCompile Include="..\src\bled\xxhash.c" />
<ClCompile Include="..\src\bled\xz_dec_bcj.c" />
<ClCompile Include="..\src\bled\xz_dec_lzma2.c" />
<ClCompile Include="..\src\bled\xz_dec_stream.c" />
<ClCompile Include="..\src\bled\zstd_decompress.c" />
<ClCompile Include="..\src\bled\zstd_decompress_block.c" />
<ClCompile Include="..\src\bled\zstd_entropy_common.c" />
<ClCompile Include="..\src\bled\zstd_error_private.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\bled\bb_archive.h" />
<ClInclude Include="..\src\bled\bled.h" />
<ClInclude Include="..\src\bled\fse.h" />
<ClInclude Include="..\src\bled\fse_bitstream.h" />
<ClInclude Include="..\src\bled\huf.h" />
<ClInclude Include="..\src\bled\libbb.h" />
<ClInclude Include="..\src\bled\platform.h" />
<ClInclude Include="..\src\bled\xxhash.h" />
<ClInclude Include="..\src\bled\xz.h" />
<ClInclude Include="..\src\bled\xz_config.h" />
<ClInclude Include="..\src\bled\xz_lzma2.h" />
<ClInclude Include="..\src\bled\xz_private.h" />
<ClInclude Include="..\src\bled\xz_stream.h" />
<ClInclude Include="..\src\bled\zstd.h" />
<ClInclude Include="..\src\bled\zstd_compiler.h" />
<ClInclude Include="..\src\bled\zstd_config.h" />
<ClInclude Include="..\src\bled\zstd_cpu.h" />
<ClInclude Include="..\src\bled\zstd_ddict.h" />
<ClInclude Include="..\src\bled\zstd_decompress_block.h" />
<ClInclude Include="..\src\bled\zstd_decompress_internal.h" />
<ClInclude Include="..\src\bled\zstd_deps.h" />
<ClInclude Include="..\src\bled\zstd_errors.h" />
<ClInclude Include="..\src\bled\zstd_error_private.h" />
<ClInclude Include="..\src\bled\zstd_internal.h" />
<ClInclude Include="..\src\bled\zstd_mem.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>bled</ProjectName>
Expand Down
72 changes: 72 additions & 0 deletions .vs/bled.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,30 @@
<ClCompile Include="..\src\bled\decompress_vtsi.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\bled\decompress_unzstd.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\bled\fse_decompress.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\bled\huf_decompress.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\bled\xxhash.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\bled\zstd_decompress.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\bled\zstd_decompress_block.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\bled\zstd_entropy_common.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\bled\zstd_error_private.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\bled\bb_archive.h">
Expand Down Expand Up @@ -116,5 +140,53 @@
<ClInclude Include="..\src\bled\xz_stream.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\fse.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\fse_bitstream.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\huf.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\xxhash.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\zstd.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\zstd_compiler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\zstd_config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\zstd_cpu.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\zstd_ddict.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\zstd_decompress_block.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\zstd_decompress_internal.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\zstd_deps.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\zstd_error_private.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\zstd_errors.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\zstd_internal.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bled\zstd_mem.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
7 changes: 4 additions & 3 deletions src/bled/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ noinst_LIBRARIES = libbled.a

libbled_a_SOURCES = bled.c crc32.c data_align.c data_extract_all.c data_skip.c decompress_bunzip2.c \
decompress_gunzip.c decompress_uncompress.c decompress_unlzma.c decompress_unxz.c decompress_unzip.c \
decompress_vtsi.c filter_accept_all.c filter_accept_list.c filter_accept_reject_list.c find_list_entry.c \
header_list.c header_skip.c header_verbose_list.c init_handle.c open_transformer.c \
seek_by_jump.c seek_by_read.c xz_dec_bcj.c xz_dec_lzma2.c xz_dec_stream.c
decompress_unzstd.c decompress_vtsi.c filter_accept_all.c filter_accept_list.c filter_accept_reject_list.c \
find_list_entry.c fse_decompress.c header_list.c header_skip.c header_verbose_list.c huf_decompress.c \
init_handle.c open_transformer.c seek_by_jump.c seek_by_read.c xz_dec_bcj.c xz_dec_lzma2.c xz_dec_stream.c \
xxhash.c zstd_decompress.c zstd_decompress_block.c zstd_entropy_common.c zstd_error_private.c
libbled_a_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/.. -Wno-undef -Wno-strict-aliasing
64 changes: 60 additions & 4 deletions src/bled/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,28 @@ am_libbled_a_OBJECTS = libbled_a-bled.$(OBJEXT) \
libbled_a-decompress_unlzma.$(OBJEXT) \
libbled_a-decompress_unxz.$(OBJEXT) \
libbled_a-decompress_unzip.$(OBJEXT) \
libbled_a-decompress_unzstd.$(OBJEXT) \
libbled_a-decompress_vtsi.$(OBJEXT) \
libbled_a-filter_accept_all.$(OBJEXT) \
libbled_a-filter_accept_list.$(OBJEXT) \
libbled_a-filter_accept_reject_list.$(OBJEXT) \
libbled_a-find_list_entry.$(OBJEXT) \
libbled_a-fse_decompress.$(OBJEXT) \
libbled_a-header_list.$(OBJEXT) \
libbled_a-header_skip.$(OBJEXT) \
libbled_a-header_verbose_list.$(OBJEXT) \
libbled_a-huf_decompress.$(OBJEXT) \
libbled_a-init_handle.$(OBJEXT) \
libbled_a-open_transformer.$(OBJEXT) \
libbled_a-seek_by_jump.$(OBJEXT) \
libbled_a-seek_by_read.$(OBJEXT) \
libbled_a-xz_dec_bcj.$(OBJEXT) \
libbled_a-xz_dec_lzma2.$(OBJEXT) \
libbled_a-xz_dec_stream.$(OBJEXT)
libbled_a-xz_dec_stream.$(OBJEXT) libbled_a-xxhash.$(OBJEXT) \
libbled_a-zstd_decompress.$(OBJEXT) \
libbled_a-zstd_decompress_block.$(OBJEXT) \
libbled_a-zstd_entropy_common.$(OBJEXT) \
libbled_a-zstd_error_private.$(OBJEXT)
libbled_a_OBJECTS = $(am_libbled_a_OBJECTS)
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
Expand Down Expand Up @@ -269,9 +276,10 @@ top_srcdir = @top_srcdir@
noinst_LIBRARIES = libbled.a
libbled_a_SOURCES = bled.c crc32.c data_align.c data_extract_all.c data_skip.c decompress_bunzip2.c \
decompress_gunzip.c decompress_uncompress.c decompress_unlzma.c decompress_unxz.c decompress_unzip.c \
decompress_vtsi.c filter_accept_all.c filter_accept_list.c filter_accept_reject_list.c find_list_entry.c \
header_list.c header_skip.c header_verbose_list.c init_handle.c open_transformer.c \
seek_by_jump.c seek_by_read.c xz_dec_bcj.c xz_dec_lzma2.c xz_dec_stream.c
decompress_unzstd.c decompress_vtsi.c filter_accept_all.c filter_accept_list.c filter_accept_reject_list.c \
find_list_entry.c fse_decompress.c header_list.c header_skip.c header_verbose_list.c huf_decompress.c \
init_handle.c open_transformer.c seek_by_jump.c seek_by_read.c xz_dec_bcj.c xz_dec_lzma2.c xz_dec_stream.c \
xxhash.c zstd_decompress.c zstd_decompress_block.c zstd_entropy_common.c zstd_error_private.c

libbled_a_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/.. -Wno-undef -Wno-strict-aliasing
all: all-am
Expand Down Expand Up @@ -395,6 +403,12 @@ libbled_a-decompress_unzip.o: decompress_unzip.c
libbled_a-decompress_unzip.obj: decompress_unzip.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-decompress_unzip.obj `if test -f 'decompress_unzip.c'; then $(CYGPATH_W) 'decompress_unzip.c'; else $(CYGPATH_W) '$(srcdir)/decompress_unzip.c'; fi`

libbled_a-decompress_unzstd.o: decompress_unzstd.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-decompress_unzstd.o `test -f 'decompress_unzstd.c' || echo '$(srcdir)/'`decompress_unzstd.c

libbled_a-decompress_unzstd.obj: decompress_unzstd.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-decompress_unzstd.obj `if test -f 'decompress_unzstd.c'; then $(CYGPATH_W) 'decompress_unzstd.c'; else $(CYGPATH_W) '$(srcdir)/decompress_unzstd.c'; fi`

libbled_a-decompress_vtsi.o: decompress_vtsi.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-decompress_vtsi.o `test -f 'decompress_vtsi.c' || echo '$(srcdir)/'`decompress_vtsi.c

Expand Down Expand Up @@ -425,6 +439,12 @@ libbled_a-find_list_entry.o: find_list_entry.c
libbled_a-find_list_entry.obj: find_list_entry.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-find_list_entry.obj `if test -f 'find_list_entry.c'; then $(CYGPATH_W) 'find_list_entry.c'; else $(CYGPATH_W) '$(srcdir)/find_list_entry.c'; fi`

libbled_a-fse_decompress.o: fse_decompress.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-fse_decompress.o `test -f 'fse_decompress.c' || echo '$(srcdir)/'`fse_decompress.c

libbled_a-fse_decompress.obj: fse_decompress.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-fse_decompress.obj `if test -f 'fse_decompress.c'; then $(CYGPATH_W) 'fse_decompress.c'; else $(CYGPATH_W) '$(srcdir)/fse_decompress.c'; fi`

libbled_a-header_list.o: header_list.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-header_list.o `test -f 'header_list.c' || echo '$(srcdir)/'`header_list.c

Expand All @@ -443,6 +463,12 @@ libbled_a-header_verbose_list.o: header_verbose_list.c
libbled_a-header_verbose_list.obj: header_verbose_list.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-header_verbose_list.obj `if test -f 'header_verbose_list.c'; then $(CYGPATH_W) 'header_verbose_list.c'; else $(CYGPATH_W) '$(srcdir)/header_verbose_list.c'; fi`

libbled_a-huf_decompress.o: huf_decompress.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-huf_decompress.o `test -f 'huf_decompress.c' || echo '$(srcdir)/'`huf_decompress.c

libbled_a-huf_decompress.obj: huf_decompress.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-huf_decompress.obj `if test -f 'huf_decompress.c'; then $(CYGPATH_W) 'huf_decompress.c'; else $(CYGPATH_W) '$(srcdir)/huf_decompress.c'; fi`

libbled_a-init_handle.o: init_handle.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-init_handle.o `test -f 'init_handle.c' || echo '$(srcdir)/'`init_handle.c

Expand Down Expand Up @@ -485,6 +511,36 @@ libbled_a-xz_dec_stream.o: xz_dec_stream.c
libbled_a-xz_dec_stream.obj: xz_dec_stream.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-xz_dec_stream.obj `if test -f 'xz_dec_stream.c'; then $(CYGPATH_W) 'xz_dec_stream.c'; else $(CYGPATH_W) '$(srcdir)/xz_dec_stream.c'; fi`

libbled_a-xxhash.o: xxhash.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-xxhash.o `test -f 'xxhash.c' || echo '$(srcdir)/'`xxhash.c

libbled_a-xxhash.obj: xxhash.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-xxhash.obj `if test -f 'xxhash.c'; then $(CYGPATH_W) 'xxhash.c'; else $(CYGPATH_W) '$(srcdir)/xxhash.c'; fi`

libbled_a-zstd_decompress.o: zstd_decompress.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-zstd_decompress.o `test -f 'zstd_decompress.c' || echo '$(srcdir)/'`zstd_decompress.c

libbled_a-zstd_decompress.obj: zstd_decompress.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-zstd_decompress.obj `if test -f 'zstd_decompress.c'; then $(CYGPATH_W) 'zstd_decompress.c'; else $(CYGPATH_W) '$(srcdir)/zstd_decompress.c'; fi`

libbled_a-zstd_decompress_block.o: zstd_decompress_block.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-zstd_decompress_block.o `test -f 'zstd_decompress_block.c' || echo '$(srcdir)/'`zstd_decompress_block.c

libbled_a-zstd_decompress_block.obj: zstd_decompress_block.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-zstd_decompress_block.obj `if test -f 'zstd_decompress_block.c'; then $(CYGPATH_W) 'zstd_decompress_block.c'; else $(CYGPATH_W) '$(srcdir)/zstd_decompress_block.c'; fi`

libbled_a-zstd_entropy_common.o: zstd_entropy_common.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-zstd_entropy_common.o `test -f 'zstd_entropy_common.c' || echo '$(srcdir)/'`zstd_entropy_common.c

libbled_a-zstd_entropy_common.obj: zstd_entropy_common.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-zstd_entropy_common.obj `if test -f 'zstd_entropy_common.c'; then $(CYGPATH_W) 'zstd_entropy_common.c'; else $(CYGPATH_W) '$(srcdir)/zstd_entropy_common.c'; fi`

libbled_a-zstd_error_private.o: zstd_error_private.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-zstd_error_private.o `test -f 'zstd_error_private.c' || echo '$(srcdir)/'`zstd_error_private.c

libbled_a-zstd_error_private.obj: zstd_error_private.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libbled_a_CFLAGS) $(CFLAGS) -c -o libbled_a-zstd_error_private.obj `if test -f 'zstd_error_private.c'; then $(CYGPATH_W) 'zstd_error_private.c'; else $(CYGPATH_W) '$(srcdir)/zstd_error_private.c'; fi`

ID: $(am__tagged_files)
$(am__define_uniq_tagged_files); mkid -fID $$unique
tags: tags-am
Expand Down
7 changes: 7 additions & 0 deletions src/bled/bb_archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ enum {
/* (unsigned) cast suppresses "integer overflow in expression" warning */
XZ_MAGIC1a = 256 * (unsigned)(256 * (256 * 0xfd + '7') + 'z') + 'X',
XZ_MAGIC2a = 256 * 'Z' + 0,
ZSTD_MAGIC1 = 0x28B5,
ZSTD_MAGIC2 = 0x2FFD,
ZSTD_MAGIC = 0x28B52FFD,
#else
COMPRESS_MAGIC = 0x9d1f,
GZIP_MAGIC = 0x8b1f,
Expand All @@ -25,6 +28,9 @@ enum {
XZ_MAGIC2 = 'z' + ('X' + ('Z' + 0 * 256) * 256) * 256,
XZ_MAGIC1a = 0xfd + ('7' + ('z' + 'X' * 256) * 256) * 256,
XZ_MAGIC2a = 'Z' + 0 * 256,
ZSTD_MAGIC1 = 0xB528,
ZSTD_MAGIC2 = 0xFD2F,
ZSTD_MAGIC = 0xFD2FB528,
#endif
};

Expand Down Expand Up @@ -290,6 +296,7 @@ IF_DESKTOP(long long) int unpack_bz2_stream(transformer_state_t *xstate) FAST_FU
IF_DESKTOP(long long) int unpack_lzma_stream(transformer_state_t *xstate) FAST_FUNC;
IF_DESKTOP(long long) int unpack_xz_stream(transformer_state_t *xstate) FAST_FUNC;
IF_DESKTOP(long long) int unpack_vtsi_stream(transformer_state_t *xstate) FAST_FUNC;
IF_DESKTOP(long long) int unpack_zstd_stream(transformer_state_t *xstate) FAST_FUNC;

char* append_ext(char *filename, const char *expected_ext) FAST_FUNC;
int bbunpack(char **argv,
Expand Down
15 changes: 9 additions & 6 deletions src/bled/bled.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Bled (Base Library for Easy Decompression)
*
* Copyright © 2014-2023 Pete Batard <[email protected]>
* Copyright © 2014-2024 Pete Batard <[email protected]>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
Expand Down Expand Up @@ -31,7 +31,9 @@ jmp_buf bb_error_jmp;
char* bb_virtual_buf = NULL;
size_t bb_virtual_len = 0, bb_virtual_pos = 0;
int bb_virtual_fd = -1;
uint32_t BB_BUFSIZE = 0x10000;
// ZSTD has a minimal buffer size of (1 << ZSTD_BLOCKSIZELOG_MAX) + ZSTD_blockHeaderSize = 128 KB + 3
// So we set our bufsize to 256 KB
uint32_t BB_BUFSIZE = 0x40000;

static long long int unpack_none(transformer_state_t *xstate)
{
Expand All @@ -49,6 +51,7 @@ unpacker_t unpacker[BLED_COMPRESSION_MAX] = {
unpack_xz_stream,
unpack_none,
unpack_vtsi_stream,
unpack_zstd_stream,
};

/* Uncompress file 'src', compressed using 'type', to file 'dst' */
Expand Down Expand Up @@ -267,7 +270,7 @@ int64_t bled_uncompress_from_buffer_to_buffer(const char* src, const size_t src_

/* Initialize the library.
* When the parameters are not NULL or zero you can:
* - specify the buffer size to use (must be larger than 64KB and a power of two)
* - specify the buffer size to use (must be larger than 256KB and a power of two)
* - specify the printf-like function you want to use to output message
* void print_function(const char* format, ...);
* - specify the read/write functions you want to use;
Expand All @@ -283,11 +286,11 @@ int bled_init(uint32_t buffer_size, printf_t print_function, read_t read_functio
if (bled_initialized)
return -1;
BB_BUFSIZE = buffer_size;
/* buffer_size must be larger than 64 KB and a power of two */
if (buffer_size < 0x10000 || (buffer_size & (buffer_size - 1)) != 0) {
/* buffer_size must be larger than 256 KB and a power of two */
if (buffer_size < 0x40000 || (buffer_size & (buffer_size - 1)) != 0) {
if (buffer_size != 0 && print_function != NULL)
print_function("bled_init: invalid buffer_size, defaulting to 64 KB");
BB_BUFSIZE = 0x10000;
BB_BUFSIZE = 0x40000;
}
bled_printf = print_function;
bled_read = read_function;
Expand Down
3 changes: 2 additions & 1 deletion src/bled/bled.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Bled (Base Library for Easy Decompression)
*
* Copyright © 2014-2015 Pete Batard <[email protected]>
* Copyright © 2014-2024 Pete Batard <[email protected]>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
Expand Down Expand Up @@ -31,6 +31,7 @@ typedef enum {
BLED_COMPRESSION_XZ, // .xz
BLED_COMPRESSION_7ZIP, // .7z
BLED_COMPRESSION_VTSI, // .vtsi
BLED_COMPRESSION_ZSTD, // .zst
BLED_COMPRESSION_MAX
} bled_compression_type;

Expand Down
Loading

0 comments on commit cef7a5c

Please sign in to comment.