This is a migrated thread and some comments may be shown as answers.

File Compression For Insert in DataBase

3 Answers 34 Views
ZipLibrary
This is a migrated thread and some comments may be shown as answers.
Jean-Charles
Top achievements
Rank 1
Jean-Charles asked on 05 Sep 2018, 08:16 AM
Language: VB.NET

Hello,

I'm looking to use CompressedStream solution without really understanding its use.

What I am trying to do:
1. compress file.
2. Insert the compressed file into my Database.
3. Retrieve compressed file to unzip it.
4. Read file.

How can I efficiently compress the file ?
Which method should I use ?
What type of variable should I deal with ? (String, Byte ()?)

Would you have a functional example in .net to help me ?

Thanks for your help

3 Answers, 1 is accepted

Sort by
0
Jean-Charles
Top achievements
Rank 1
answered on 05 Sep 2018, 08:18 AM

I have read this documentation:

https://docs.telerik.com/devtools/document-processing/libraries/radziplibrary/features/compress-stream

but it does not help me to understand

0
Jean-Charles
Top achievements
Rank 1
answered on 07 Sep 2018, 06:16 AM

Pour les intéressés :)

It's better to work on bytes rather than text ...
So no streamreader & co ...

 

Public encryptionSettings As New DefaultEncryptionSettings()
Public PassKey As String = "MOTDEPASSEDELAMORTQUITUE"
Public result As Byte()
 
Public Function Compress(filebuffer As Byte()) As Byte()
    Using outputStream As New MemoryStream()
        Using inputStream As New MemoryStream(filebuffer)
 
            encryptionSettings.Password = PassKey
 
            Dim compressionSettings As New LzmaSettings()
            compressionSettings.DictionarySize = 26
            compressionSettings.FastBytes = 155
            compressionSettings.LiteralContextBits = 4
            compressionSettings.LiteralPositionBits = 1
            compressionSettings.MatchFinderType = LzmaMatchFinderType.BT4
            compressionSettings.PositionStateBits = 1
 
            Using compressedStream As New CompressedStream(outputStream, StreamOperationMode.Write, compressionSettings, Nothing, encryptionSettings)
                inputStream.CopyTo(compressedStream)
                compressedStream.Flush()
            End Using
        End Using
        result = outputStream.ToArray
    End Using
    Return result
End Function
 
Public Function UnCompress(filebuffer As Byte()) As Byte()
    Dim result As Byte()
    Using outputStream As New MemoryStream()
        Using inputStream As New MemoryStream(filebuffer)
 
            Dim encryptionSettings As New DefaultEncryptionSettings()
            encryptionSettings.Password = PassKey
 
 
            Using compressedStream As New CompressedStream(inputStream, StreamOperationMode.Read, New LzmaSettings(), Nothing, encryptionSettings)
                compressedStream.CopyTo(outputStream)
            End Using
        End Using
        result = outputStream.ToArray
    End Using
 
    Dim MyOutputStream As IO.MemoryStream
    MyOutputStream = New MemoryStream(result.ToArray)
    Form_reader.RadPdfViewer1.LoadDocument(MyOutputStream)
    Form_reader.Show()
 
    Return result
End Function

 

0
Tanya
Telerik team
answered on 07 Sep 2018, 05:08 PM
Hi Jean-Charles,

I am happy to hear that you managed to implement the desired behavior.

Something additional I would like to mention is that you can create directly ZIP files if you prefer to. To achieve that, you can use the ZipFile class enabling you to easily add and extract files to/from a ZipArchive. VB.NET snippets are currently not available for the Telerik Document Processing documentation but you could use http://converter.telerik.com/ to convert the C# code.

Hope this is helpful.

Regards,
Tanya
Progress Telerik

Tags
ZipLibrary
Asked by
Jean-Charles
Top achievements
Rank 1
Answers by
Jean-Charles
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or