common.bmx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. ' Copyright (c) 2022-2025 Bruce A Henderson
  2. ' All rights reserved.
  3. '
  4. ' Redistribution and use in source and binary forms, with or without
  5. ' modification, are permitted provided that the following conditions are met:
  6. ' * Redistributions of source code must retain the above copyright
  7. ' notice, this list of conditions and the following disclaimer.
  8. ' * Redistributions in binary form must reproduce the above copyright
  9. ' notice, this list of conditions and the following disclaimer in the
  10. ' documentation and/or other materials provided with the distribution.
  11. '
  12. ' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY
  13. ' EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  14. ' WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  15. ' DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
  16. ' DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  17. ' (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  18. ' LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  19. ' ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. ' (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21. ' SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. '
  23. SuperStrict
  24. Import "source.bmx"
  25. Extern
  26. Function bmx_libarchive_read_archive_new:Byte Ptr()
  27. Function bmx_libarchive_archive_read_open_memory:Int(handle:Byte Ptr, buf:Byte Ptr, size:Size_T)
  28. Function bmx_libarchive_archive_read_next_header:Int(handle:Byte Ptr, entry:Byte Ptr)
  29. Function bmx_libarchive_archive_read_data_skip:Int(handle:Byte Ptr)
  30. Function bmx_libarchive_archive_read_open:Int(handle:Byte Ptr, data:Object)
  31. Function bmx_libarchive_archive_read_set_read_callback:Int(handle:Byte Ptr)
  32. Function bmx_libarchive_archive_read_set_seek_callback:Int(handle:Byte Ptr)
  33. Function bmx_libarchive_archive_read_set_callback_data:Int(handle:Byte Ptr, callbackData:Object)
  34. Function bmx_libarchive_archive_read_data:Int(handle:Byte Ptr, buf:Byte Ptr, size:Size_T)
  35. Function bmx_libarchive_archive_read_add_passphrase:Int(handle:Byte Ptr, passphrase:String)
  36. Function bmx_libarchive_archive_read_has_encrypted_entries:Int(handle:Byte Ptr)
  37. Function bmx_libarchive_archive_read_set_filter_option:Int(handle:Byte Ptr, option:String, value:String, moduleName:String)
  38. Function bmx_libarchive_archive_read_set_format_option:Int(handle:Byte Ptr, option:String, value:String, moduleName:String)
  39. Function bmx_libarchive_archive_read_set_passphrase_callback:Int(handle:Byte Ptr, data:Object)
  40. Function archive_read_set_read_callback:Int(handle:Byte Ptr, cb:Int(arc:Byte Ptr, cbData:Object, block:Byte Ptr Ptr))
  41. Function bmx_libarchive_archive_read_free:Int(handle:Byte Ptr)
  42. Function bmx_libarchive_write_archive_new:Byte Ptr()
  43. Function bmx_libarchive_archive_write_free:Int(handle:Byte Ptr)
  44. Function bmx_libarchive_archive_write_open_memory:Int(handle:Byte Ptr, buf:Byte Ptr, size:Int, used:Int Ptr)
  45. Function bmx_libarchive_archive_write_data:Int(handle:Byte Ptr, data:Byte Ptr, size:Size_T)
  46. Function bmx_libarchive_archive_write_header:Int(handle:Byte Ptr, entry:Byte Ptr)
  47. Function bmx_libarchive_archive_write_close:Int(handle:Byte Ptr)
  48. Function bmx_libarchive_archive_write_finish_entry:Int(handle:Byte Ptr)
  49. Function bmx_libarchive_archive_write_set_passphrase:Int(handle:Byte Ptr, passphrase:String)
  50. Function bmx_libarchive_archive_write_set_filter_option:Int(handle:Byte Ptr, option:String, value:String, moduleName:String)
  51. Function bmx_libarchive_archive_write_set_format_option:Int(handle:Byte Ptr, option:String, value:String, moduleName:String)
  52. Function bmx_libarchive_archive_write_open:Int(handle:Byte Ptr, data:Object)
  53. Function bmx_libarchive_archive_write_set_option:Int(handle:Byte Ptr, option:String, value:String, moduleName:String)
  54. Function bmx_libarchive_archive_clear_error(handle:Byte Ptr)
  55. Function bmx_libarchive_archive_errno:Int(handle:Byte Ptr)
  56. Function bmx_libarchive_archive_error_string:String(handle:Byte Ptr)
  57. Function bmx_libarchive_archive_file_count:Int(handle:Byte Ptr)
  58. Function bmx_libarchive_archive_filter_code:Int(handle:Byte Ptr, filter:Int)
  59. Function bmx_libarchive_archive_filter_count:Int(handle:Byte Ptr)
  60. Function bmx_libarchive_archive_filter_name:String(handle:Byte Ptr, filter:Int)
  61. Function bmx_libarchive_archive_format:Int(handle:Byte Ptr)
  62. Function bmx_libarchive_archive_format_name:String(handle:Byte Ptr)
  63. Function bmx_libarchive_archive_position(handle:Byte Ptr, filter:Int, v:Long Ptr)
  64. Function bmx_libarchive_archive_entry_new:Byte Ptr()
  65. Function bmx_libarchive_archive_entry_free(handle:Byte Ptr)
  66. Function bmx_libarchive_archive_entry_clear:Byte Ptr(handle:Byte Ptr)
  67. Function bmx_libarchive_archive_entry_clone:Byte Ptr(handle:Byte Ptr)
  68. Function bmx_libarchive_archive_entry_hardlink:String(handle:Byte Ptr)
  69. Function bmx_libarchive_archive_entry_symlink:String(handle:Byte Ptr)
  70. Function bmx_libarchive_archive_entry_pathname:String(handle:Byte Ptr)
  71. Function bmx_libarchive_archive_entry_set_link(handle:Byte Ptr, path:String)
  72. Function bmx_libarchive_archive_entry_set_pathname(handle:Byte Ptr, path:String)
  73. Function bmx_libarchive_archive_entry_set_symlink(handle:Byte Ptr, path:String)
  74. Function bmx_libarchive_archive_entry_set_size(handle:Byte Ptr, size:Long)
  75. Function bmx_libarchive_archive_entry_unset_size(handle:Byte Ptr)
  76. Function bmx_libarchive_archive_entry_set_ctime(handle:Byte Ptr, time:Long, nanoseconds:Long)
  77. Function bmx_libarchive_archive_entry_set_mtime(handle:Byte Ptr, time:Long, nanoseconds:Long)
  78. Function bmx_libarchive_archive_entry_set_filetype(handle:Byte Ptr, fType:EArchiveFileType)
  79. Function bmx_libarchive_archive_entry_set_perm(handle:Byte Ptr, perm:Int)
  80. Function bmx_libarchive_archive_entry_is_data_encrypted:Int(handle:Byte Ptr)
  81. Function bmx_libarchive_archive_entry_is_metadata_encrypted:Int(handle:Byte Ptr)
  82. Function bmx_libarchive_archive_entry_is_encrypted:Int(handle:Byte Ptr)
  83. Function bmx_libarchive_archive_entry_size_is_set:Int(handle:Byte Ptr)
  84. Function bmx_libarchive_archive_entry_size:Long(handle:Byte Ptr)
  85. Function bmx_libarchive_archive_entry_atime:Long(handle:Byte Ptr)
  86. Function bmx_libarchive_archive_entry_atime_nsec:Long(handle:Byte Ptr)
  87. Function bmx_libarchive_archive_entry_atime_is_set:Int(handle:Byte Ptr)
  88. Function bmx_libarchive_archive_entry_birthtime:Long(handle:Byte Ptr)
  89. Function bmx_libarchive_archive_entry_birthtime_nsec:Long(handle:Byte Ptr)
  90. Function bmx_libarchive_archive_entry_birthtime_is_set:Int(handle:Byte Ptr)
  91. Function bmx_libarchive_archive_entry_ctime:Int(handle:Byte Ptr)
  92. Function bmx_libarchive_archive_entry_ctime_nsec:Int(handle:Byte Ptr)
  93. Function bmx_libarchive_archive_entry_ctime_is_set:Int(handle:Byte Ptr)
  94. Function bmx_libarchive_archive_entry_set_atime(handle:Byte Ptr, atime:Long, nanoseconds:Long)
  95. Function bmx_libarchive_archive_entry_unset_atime(handle:Byte Ptr)
  96. Function bmx_libarchive_archive_entry_set_birthtime(handle:Byte Ptr, btime:Long, nanoseconds:Long)
  97. Function bmx_libarchive_archive_entry_unset_birthtime(handle:Byte Ptr)
  98. Function bmx_libarchive_archive_entry_unset_ctime(handle:Byte Ptr)
  99. Function bmx_libarchive_archive_entry_filetype:EArchiveFileType(handle:Byte Ptr)
  100. Function bmx_libarchive_archive_entry_mtime:Int(handle:Byte Ptr)
  101. Function bmx_libarchive_archive_entry_mtime_nsec:Int(handle:Byte Ptr)
  102. Function bmx_libarchive_archive_entry_mtime_is_set:Int(handle:Byte Ptr)
  103. Function bmx_libarchive_archive_entry_unset_mtime(handle:Byte Ptr)
  104. Function archive_error_string:Byte Ptr(handle:Byte Ptr)
  105. End Extern
  106. Enum EArchiveFilter
  107. NONE
  108. GZIP
  109. BZIP2
  110. COMPRESS
  111. PROGRAM
  112. LZMA
  113. XZ
  114. UU
  115. RPM
  116. LZIP
  117. LRZIP
  118. LZOP
  119. GRZIP
  120. LZ4
  121. ZSTD
  122. End Enum
  123. Enum EArchiveFormat
  124. CPIO = $10000
  125. CPIO_POSIX = $10000 | 1
  126. CPIO_BIN = $10000 | 2
  127. CPIO_SVR4_NOCRC = $10000 | 4
  128. CPIO_PWB = $10000 | 7
  129. SHAR = $20000
  130. TAR = $30000
  131. USTAR = $30000 | 1
  132. PAX = $30000 | 3
  133. GNUTAR = $30000 | 4
  134. ISO9660 = $40000
  135. ZIP = $50000
  136. EMPTY = $60000
  137. AR = $70000
  138. AR_GNU = $70000 | 1
  139. AR_BSD = $70000 | 2
  140. MTREE = $80000
  141. RAW = $90000
  142. XAR = $A0000
  143. LHA = $B0000
  144. CAB = $C0000
  145. RAR = $D0000
  146. SEVEN_ZIP = $E0000
  147. WARC = $F0000
  148. RAR_V5 = $100000
  149. End Enum
  150. Enum EArchiveFileType:UInt
  151. File = 32768 ' regular file - 0100000 (octal)
  152. Link = 40960 ' symbolic link - 0120000
  153. Socket = 49152 ' socket - 0140000
  154. CharDevice = 8192 ' character device - 0020000
  155. BlockDevice = 24576 ' block device - 0060000
  156. Dir = 16384 ' directory - 0040000
  157. Fifo = 4096 ' named pipe - 0010000
  158. End Enum
  159. Enum EArchiveEncryptionType
  160. Zip
  161. AES128
  162. AES256
  163. End Enum
  164. Const ARCHIVE_FILTER_NONE:Int = 0
  165. Const ARCHIVE_FILTER_GZIP:Int = 1
  166. Const ARCHIVE_FILTER_BZIP2:Int = 2
  167. Const ARCHIVE_FILTER_COMPRESS:Int = 3
  168. Const ARCHIVE_FILTER_PROGRAM:Int = 4
  169. Const ARCHIVE_FILTER_LZMA:Int = 5
  170. Const ARCHIVE_FILTER_XZ:Int = 6
  171. Const ARCHIVE_FILTER_UU:Int = 7
  172. Const ARCHIVE_FILTER_RPM:Int = 8
  173. Const ARCHIVE_FILTER_LZIP:Int = 9
  174. Const ARCHIVE_FILTER_LRZIP:Int = 10
  175. Const ARCHIVE_FILTER_LZOP:Int = 11
  176. Const ARCHIVE_FILTER_GRZIP:Int = 12
  177. Const ARCHIVE_FILTER_LZ4:Int = 13
  178. Const ARCHIVE_FILTER_ZSTD:Int = 14
  179. Const ARCHIVE_FORMAT_BASE_MASK:Int = $ff0000
  180. Const ARCHIVE_FORMAT_CPIO:Int = $10000
  181. Const ARCHIVE_FORMAT_CPIO_POSIX:Int = ARCHIVE_FORMAT_CPIO | 1
  182. Const ARCHIVE_FORMAT_CPIO_BIN_LE:Int = ARCHIVE_FORMAT_CPIO | 2
  183. Const ARCHIVE_FORMAT_CPIO_BIN_BE:Int = ARCHIVE_FORMAT_CPIO | 3
  184. Const ARCHIVE_FORMAT_CPIO_SVR4_NOCRC:Int = ARCHIVE_FORMAT_CPIO | 4
  185. Const ARCHIVE_FORMAT_CPIO_SVR4_CRC:Int = ARCHIVE_FORMAT_CPIO | 5
  186. Const ARCHIVE_FORMAT_CPIO_AFIO_LARGE:Int = ARCHIVE_FORMAT_CPIO | 6
  187. Const ARCHIVE_FORMAT_SHAR:Int = $20000
  188. Const ARCHIVE_FORMAT_SHAR_BASE:Int = ARCHIVE_FORMAT_SHAR | 1
  189. Const ARCHIVE_FORMAT_SHAR_DUMP:Int = ARCHIVE_FORMAT_SHAR | 2
  190. Const ARCHIVE_FORMAT_TAR:Int = $30000
  191. Const ARCHIVE_FORMAT_TAR_USTAR:Int = ARCHIVE_FORMAT_TAR | 1
  192. Const ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE:Int = ARCHIVE_FORMAT_TAR | 2
  193. Const ARCHIVE_FORMAT_TAR_PAX_RESTRICTED:Int = ARCHIVE_FORMAT_TAR | 3
  194. Const ARCHIVE_FORMAT_TAR_GNUTAR:Int = ARCHIVE_FORMAT_TAR | 4
  195. Const ARCHIVE_FORMAT_ISO9660:Int = $40000
  196. Const ARCHIVE_FORMAT_ISO9660_ROCKRIDGE:Int = ARCHIVE_FORMAT_ISO9660 | 1
  197. Const ARCHIVE_FORMAT_ZIP:Int = $50000
  198. Const ARCHIVE_FORMAT_EMPTY:Int = $60000
  199. Const ARCHIVE_FORMAT_AR:Int = $70000
  200. Const ARCHIVE_FORMAT_AR_GNU:Int = ARCHIVE_FORMAT_AR | 1
  201. Const ARCHIVE_FORMAT_AR_BSD:Int = ARCHIVE_FORMAT_AR | 2
  202. Const ARCHIVE_FORMAT_MTREE:Int = $80000
  203. Const ARCHIVE_FORMAT_RAW:Int = $90000
  204. Const ARCHIVE_FORMAT_XAR:Int = $A0000
  205. Const ARCHIVE_FORMAT_LHA:Int = $B0000
  206. Const ARCHIVE_FORMAT_CAB:Int = $C0000
  207. Const ARCHIVE_FORMAT_RAR:Int = $D0000
  208. Const ARCHIVE_FORMAT_7ZIP:Int = $E0000
  209. Const ARCHIVE_FORMAT_WARC:Int = $F0000
  210. Const ARCHIVE_FORMAT_RAR_V5:Int = $100000
  211. Rem
  212. bbdoc: Found end of archive.
  213. End Rem
  214. Const ARCHIVE_EOF:Int = 1
  215. Rem
  216. bbdoc: Operation was successful.
  217. End Rem
  218. Const ARCHIVE_OK:Int = 0
  219. Rem
  220. bbdoc: Retry might succeed.
  221. End Rem
  222. Const ARCHIVE_RETRY:Int = -10
  223. Rem
  224. bbdoc: Partial success.
  225. End Rem
  226. Const ARCHIVE_WARN:Int = -20
  227. Rem
  228. bbdoc: Current operation cannot complete.
  229. about: For example, if WriteHeader "fails", tThen you can't push data.
  230. End Rem
  231. Const ARCHIVE_FAILED:Int = -25
  232. Rem
  233. bbdoc: No more operations are possible.
  234. about: For example, if WriteHeader is "fatal," then this archive is dead and useless.
  235. End Rem
  236. Const ARCHIVE_FATAL:Int = -30
  237. Const ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED:Int = -2
  238. Const ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW:Int = -1