;
; ------------------------------------------------------------
;
; PureBasic - Compressor example file
;
; (c) 2001 - Fantaisie Software
;
; ------------------------------------------------------------
;
If ReadFile(0, OpenFileRequester("Choose a file to compress", "", "*.*", 0))
FileLength = Lof(0)
; Allocate the 2 memory buffers needed for compression..
;
*Source = AllocateMemory(FileLength)
*Target = AllocateMemory(FileLength+8)
If FileLength And *Source And *Target
ReadData(0, *Source, FileLength) ; Read the whole file in the memory buffer
; Compress our file, which is in memory (and use a timer to see the time spend by compression..)
;
CompressedLength = PackMemory(*Source, *Target, FileLength)
If CompressedLength
DecompressedLength = UnpackMemory(*Target, *Source)
If DecompressedLength = FileLength
MessageRequester("Info", "De/Compression succeded:"+Chr(10)+Chr(10)+"Old size: "+Str(FileLength)+Chr(10)+"New size: "+Str(CompressedLength))
EndIf
EndIf
FreeMemory(*Source)
FreeMemory(*Target)
EndIf
CloseFile(0)
EndIf
End