'LZMA 编码，压缩（不支持64位，因为没64位库）
#Include Once "inc/lzma.bi"

'--------------------------------------------------------------------------
Function LzmaEncode(inBy() As UByte, OutBy() As UByte) As Integer '
   Dim As UInteger InBufferSize,DstSize,LzmaRet,Dst
   Dim Hdr As Lzma_FileHdr Ptr  '附带头部
   InBufferSize = UBound(inBy) + 1 '输入长度
   DstSize = InBufferSize + SizeOf(Lzma_FileHdr) '估计输出长度
   ReDim OutBy(DstSize -1)
   Hdr = @OutBy(0)
   Hdr->FileSize = InBufferSize '保存输入长度，解压用
   Dst = @OutBy(0) + SizeOf(Lzma_FileHdr) '实际输出开始地址
   '@Hdr->LzmaProp(0)  解压必须要用到这个
   'Print "Dst=" & Dst
   'Print "DstSize=" & DstSize
   LzmaRet = LzmaCompress(dst, DstSize, @InBy(0), InBufferSize, @Hdr->LzmaProp(0), LZMA_PROPS_SIZE)
   If LzmaRet = 0 Then
      'Print "DstSize=" & DstSize
      ReDim Preserve OutBy(SizeOf(Lzma_FileHdr) + DstSize -1) '设置实际压缩后的大小
      Function = DstSize
   Else
      Function = 0
   End If
   
End Function