Results 1 to 6 of 6

Thread: ZSTD decompress

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2019
    Posts
    14

    Talking ZSTD decompress

    the decompress function need to size of destination array so, if know the origin size as compress, can decompress. but generally any compressed bytes cannot be known origin byte size. how do you make the classes and modules?

    Compression_ZSTD.zip

    https://facebook.github.io/zstd/
    Last edited by AmSOL; Jun 28th, 2020 at 10:23 PM.

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,844

    Re: ZSTD decompress

    I use this DLL provided by wqweto
    https://github.com/wqweto/zstd/releases

    Regarding your question about knowing the original size of an array.
    That's something you have to store yourself.
    You should not just store a blob of compressed data somewhere without describing the data.
    The least thing you should store is the original size of the data stream.

    Have a look at a ZIP file, in this archive format a lot of additional information is stored.
    The filename, the date/time stamp, the original file size, the CRC32 value
    And it can even store multiple files, including a folder structure.

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2019
    Posts
    14

    Re: ZSTD decompress

    The link is bad if you care to change it..
    I tried https://github.com/wqweto/zstd.

    I don't actually see any vb6 resources ..
    Could you perhaps give some more help

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,844

    Re: ZSTD decompress

    Can you first explain what your original problem is?

    What kind of VB6 resources do you expect?
    Code:
    ' https://github.com/wqweto/zstd/releases
    
    ' ZStandard compression
    Private Declare Function ZSTD_compress Lib "zstdlib-x86.dll" (Dst As Any, ByVal maxDstSize As Long, src As Any, ByVal srcSize As Long, ByVal CompressionLevel As Long) As Long
    Private Declare Function ZSTD_decompress Lib "zstdlib-x86.dll" (Dst As Any, ByVal maxDstSize As Long, src As Any, ByVal srcSize As Long) As Long
    
    Private Function ZSTDCompressData(theData() As Byte, Optional ByVal CompressionLevel As Long = 5) As Long
      Dim TempBuffer() As Byte
      Dim lTemp As Long, lSize As Long
      
      On Error GoTo errHandler
      
      ' Above 18 gives strange results with the current DLL
      If CompressionLevel > 18 Then CompressionLevel = 18
      If CompressionLevel = 0 Then CompressionLevel = 14
      
      lSize = 2 * (UBound(theData) + 1)
      ReDim TempBuffer(0 To lSize) As Byte
      lSize = ZSTD_compress(TempBuffer(0), UBound(TempBuffer) + 1, theData(0), UBound(theData) + 1, CompressionLevel)
      If lSize > 0 Then
        lTemp = UBound(theData) + 1
          
        'Truncate to compressed size
        ReDim Preserve theData(lSize - 1)
        CopyMemory theData(0), TempBuffer(0), lSize
        ZSTDCompressData = 0
      Else
        ZSTDCompressData = lSize
      End If
      Exit Function
    
    errHandler:
      ZSTDCompressData = -1
    End Function
    
    Private Function ZSTDDecompressData(theData() As Byte, lDestLen As Long) As Long
      Dim TempBuffer() As Byte
      Dim lResult As Long
      
      On Error GoTo errHandler
      
      ZSTDDecompressData = -1
      If lDestLen > 0 Then
        ReDim TempBuffer(0 To lDestLen - 1) As Byte
        lResult = ZSTD_decompress(TempBuffer(0), lDestLen, theData(0), UBound(theData) + 1)
        theData = TempBuffer
        If lResult > 0 Then ZSTDDecompressData = 0 Else ZSTDDecompressData = lResult
      End If
      Exit Function
      
    errHandler:
    End Function
    For further discussion about compression libraries:
    http://www.vbforums.com/showthread.p...ession-library

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2019
    Posts
    14

    Re: ZSTD decompress

    It must pass a byte array into string and then back to byte array which I suppose vbunicode would be fine, bit I don't think I understand the DLL how its destination works on how the file or data is outputted. I mean if the call included the ldestlen and byte array but nothing was varient and the data just goes to DLL somewhere.

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,844

    Re: ZSTD decompress

    Did you check the code I posted?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width