Having trobule with packer
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Chevron.
Hi,Firstly as a new user I would like to say Hi to all.
Heres my first problem.
Im having trobule with the packer example, it only seems to work for small files, heres the demo code
If ReadFile(0, OpenFileRequester("Choose a file to compress", "", "*.*", 0))
FileLength = Lof()
; Allocate the 2 memory buffers needed for compression..
;
If FileLength And AllocateMemory(0, FileLength , 0) And AllocateMemory(1, FileLength+8, 0)
ReadData(UseMemory(0), 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..)
;
StartTimer = GetTickCount_()
CompressedLength = PackMemory(UseMemory(0), UseMemory(1), FileLength)
If CompressedLength
CompressionTime = GetTickCount_()-StartTimer
StartTimer = GetTickCount_()
DecompressedLength = UnpackMemory(UseMemory(1), UseMemory(0))
If DecompressedLength = FileLength
DecompressionTime = GetTickCount_()-StartTimer
MessageRequester("Info", "De/Compression succeded:"+Chr(10)+Chr(10)+"Old size: "+Str(FileLength)+Chr(10)+"New size:"+Str(CompressedLength)+Chr(10)+"Compression time: "+Str(CompressionTime)+" ms"+Chr(10)+"Decompression Time: "+Str(DecompressionTime)+" ms", #MB_ICONINFORMATION)
EndIf
EndIf
EndIf
EndIf
End
Any pointers would be greatly appreicated.
Hi,Firstly as a new user I would like to say Hi to all.
Heres my first problem.
Im having trobule with the packer example, it only seems to work for small files, heres the demo code
If ReadFile(0, OpenFileRequester("Choose a file to compress", "", "*.*", 0))
FileLength = Lof()
; Allocate the 2 memory buffers needed for compression..
;
If FileLength And AllocateMemory(0, FileLength , 0) And AllocateMemory(1, FileLength+8, 0)
ReadData(UseMemory(0), 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..)
;
StartTimer = GetTickCount_()
CompressedLength = PackMemory(UseMemory(0), UseMemory(1), FileLength)
If CompressedLength
CompressionTime = GetTickCount_()-StartTimer
StartTimer = GetTickCount_()
DecompressedLength = UnpackMemory(UseMemory(1), UseMemory(0))
If DecompressedLength = FileLength
DecompressionTime = GetTickCount_()-StartTimer
MessageRequester("Info", "De/Compression succeded:"+Chr(10)+Chr(10)+"Old size: "+Str(FileLength)+Chr(10)+"New size:"+Str(CompressedLength)+Chr(10)+"Compression time: "+Str(CompressionTime)+" ms"+Chr(10)+"Decompression Time: "+Str(DecompressionTime)+" ms", #MB_ICONINFORMATION)
EndIf
EndIf
EndIf
EndIf
End
Any pointers would be greatly appreicated.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
Good luck!
Hi and welcome, one question -how large files are you trying to compress? I did a small test once on a aprox 2M Byte file and it took, if i'm not remembering wrong, several minutes to compress this. You see the compression is very slow, but the decompression is fast... So it might seem like the example totaly locks up when in reality it's just taking it's time compressing.Im having trobule with the packer example, it only seems to work for small files, heres the demo code
Good luck!
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Chevron.
No its not that, it seems to be that the filesize bit is returning the wrong value for some reason, the rotiune quits on error. heres another easier to follow version, which doesn't work for me either:
filename$= OpenFileRequester("Choose a file to compress", "", "*.*", 0))
MessageRequester("Information", "Selected File: "+Filename$, 0);
FileLength.l = FileSize(filename$)
MessageRequester("Information", "File size: "+Str(FileLenght.l),0);THIS LINE RETURNS STRANGE VALUES
; Allocate the 2 memory buffers needed for compression..
;
If FileLength.l And AllocateMemory(0, FileLength.l , 0) And AllocateMemory(1, FileLength.l+8,#PB_MessageRequester_Ok)
ReadData(UseMemory(0), 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..)
;
StartTimer = GetTickCount_()
CompressedLength = PackMemory(UseMemory(0), UseMemory(1), FileLength.l)
If CompressedLength
CompressionTime = GetTickCount_()-StartTimer
StartTimer = GetTickCount_()
DecompressedLength = UnpackMemory(UseMemory(1), UseMemory(0))
If DecompressedLength = FileLength
DecompressionTime = GetTickCount_()-StartTimer
MessageRequester("Info", "De/Compression succeded:"+Chr(10)+Chr(10)+"Old size: "+Str(FileLength.l)+Chr(10)+"New size:"+Str(CompressedLength)+Chr(10)+"Compression time: "+Str(CompressionTime)+" ms"+Chr(10)+"Decompression Time: "+Str(DecompressionTime)+" ms", #MB_ICONINFORMATION)
EndIf
EndIf
EndIf
End
No its not that, it seems to be that the filesize bit is returning the wrong value for some reason, the rotiune quits on error. heres another easier to follow version, which doesn't work for me either:
filename$= OpenFileRequester("Choose a file to compress", "", "*.*", 0))
MessageRequester("Information", "Selected File: "+Filename$, 0);
FileLength.l = FileSize(filename$)
MessageRequester("Information", "File size: "+Str(FileLenght.l),0);THIS LINE RETURNS STRANGE VALUES
; Allocate the 2 memory buffers needed for compression..
;
If FileLength.l And AllocateMemory(0, FileLength.l , 0) And AllocateMemory(1, FileLength.l+8,#PB_MessageRequester_Ok)
ReadData(UseMemory(0), 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..)
;
StartTimer = GetTickCount_()
CompressedLength = PackMemory(UseMemory(0), UseMemory(1), FileLength.l)
If CompressedLength
CompressionTime = GetTickCount_()-StartTimer
StartTimer = GetTickCount_()
DecompressedLength = UnpackMemory(UseMemory(1), UseMemory(0))
If DecompressedLength = FileLength
DecompressionTime = GetTickCount_()-StartTimer
MessageRequester("Info", "De/Compression succeded:"+Chr(10)+Chr(10)+"Old size: "+Str(FileLength.l)+Chr(10)+"New size:"+Str(CompressedLength)+Chr(10)+"Compression time: "+Str(CompressionTime)+" ms"+Chr(10)+"Decompression Time: "+Str(DecompressionTime)+" ms", #MB_ICONINFORMATION)
EndIf
EndIf
EndIf
End
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> FileLength.l = FileSize(filename$)
> MessageRequester("Information", "File size: "+Str(FileLength.l),0);THIS LINE RETURNS STRANGE VALUES
The above works fine for me... so please tell us the actual size of the file
that you're testing with it -- it's not bigger than 2,147,483,647 by any chance?
PB - Registered PureBasic Coder
Edited by - PB on 04 August 2002 01:01:51
> FileLength.l = FileSize(filename$)
> MessageRequester("Information", "File size: "+Str(FileLength.l),0);THIS LINE RETURNS STRANGE VALUES
The above works fine for me... so please tell us the actual size of the file
that you're testing with it -- it's not bigger than 2,147,483,647 by any chance?
PB - Registered PureBasic Coder
Edited by - PB on 04 August 2002 01:01:51
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Chevron.
Right well ive got the filesize working, just a silly mistake. But the packed size seems to be too small . Im receiving a result of around 166bytes for a 2.2meg file??
heres the code again, stripped a little:
file_name$= OpenFileRequester("Choose a file to compress", "", "*.*", 0))
MessageRequester("Information", "Selected File: "+File_name$, 0);
Len.l = FileSize(file_name$)
MessageRequester("Information", "File size: "+(Str(Len.l)),0)
; Allocate the 2 memory buffers needed for compression..
;
If Len.l And AllocateMemory(0,Len.l,0) And AllocateMemory(1,(Len.l)+8,1)
ReadData(UseMemory(0),Len.l) ; 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..)
;
StartTimer = GetTickCount_()
CompressedLength.l = PackMemory(UseMemory(0),UseMemory(1),Len.l)
MessageRequester("Info", "Compression succeded:"+Chr(10)+Chr(10)+"Old size: "+Str(Len.l)+Chr(10)+"New size:"+Str(CompressedLength.l)+Chr(10), #MB_ICONINFORMATION)
EndIf
End
Right well ive got the filesize working, just a silly mistake. But the packed size seems to be too small . Im receiving a result of around 166bytes for a 2.2meg file??
heres the code again, stripped a little:
file_name$= OpenFileRequester("Choose a file to compress", "", "*.*", 0))
MessageRequester("Information", "Selected File: "+File_name$, 0);
Len.l = FileSize(file_name$)
MessageRequester("Information", "File size: "+(Str(Len.l)),0)
; Allocate the 2 memory buffers needed for compression..
;
If Len.l And AllocateMemory(0,Len.l,0) And AllocateMemory(1,(Len.l)+8,1)
ReadData(UseMemory(0),Len.l) ; 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..)
;
StartTimer = GetTickCount_()
CompressedLength.l = PackMemory(UseMemory(0),UseMemory(1),Len.l)
MessageRequester("Info", "Compression succeded:"+Chr(10)+Chr(10)+"Old size: "+Str(Len.l)+Chr(10)+"New size:"+Str(CompressedLength.l)+Chr(10), #MB_ICONINFORMATION)
EndIf
End
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
Anyway do it this way and you should have some realistic results:
Edited by - Pupil on 04 August 2002 10:34:46
You really should compile with the debugger enabled, then you would have noticed that you're trying to read from a file that you haven't opened...Right well ive got the filesize working, just a silly mistake. But the packed size seems to be too small . Im receiving a result of around 166bytes for a 2.2meg file??
heres the code again, stripped a little:
Anyway do it this way and you should have some realistic results:
Code: Select all
file_name$= OpenFileRequester("Choose a file to compress", "", "*.*", 0))
MessageRequester("Information", "Selected File: "+file_name$, 0);
Len.l = FileSize(file_name$)
MessageRequester("Information", "File size: "+(Str(Len.l)),0)
; Allocate the 2 memory buffers needed for compression..
;
If Len.l And AllocateMemory(0,Len.l,0) And AllocateMemory(1,(Len.l)+8,1)
If ReadFile(0, file_name$)
ReadData(UseMemory(0),Len.l) ; Read the whole file in the memory buffer
StartTimer = GetTickCount_()
CompressedLength.l = PackMemory(UseMemory(0),UseMemory(1),Len.l)
msg$ = "Compression succeded:"+Chr(10)+Chr(10)+"Old size: "
msg$ + Str(Len.l)+Chr(10)+"New size:"+Str(CompressedLength.l)+Chr(10)
MessageRequester("Info", msg$, #MB_ICONINFORMATION)
CloseFile(0)
EndIf
EndIf
End
Edited by - Pupil on 04 August 2002 10:34:46
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> hee,hee, yep does seem to be correct, it expands ok. Thanks for the help PB
I was only kidding... you're saying a 166-byte file expands to 2.2 MB?
Nah, there has to be something very wrong there... that's impossible.
PB - Registered PureBasic Coder
> hee,hee, yep does seem to be correct, it expands ok. Thanks for the help PB
I was only kidding... you're saying a 166-byte file expands to 2.2 MB?
Nah, there has to be something very wrong there... that's impossible.
PB - Registered PureBasic Coder
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
Well actually it's not impossible, it merely depends heavily on the file you're compressing, if the file is filled with 2.2MB of zeros and depending on algorithm you could get away with much less than 166 Bytes 
But normaly you shouldn't get that kind of compression, seems very unlikely to me!
Chevron, try to make a file filled with random numbers only, this kind of file shouldn't compress anything at all if it's big enough.
Only PureBasic makes it possibleI was only kidding... you're saying a 166-byte file expands to 2.2 MB?
Nah, there has to be something very wrong there... that's impossible.
But normaly you shouldn't get that kind of compression, seems very unlikely to me!
Chevron, try to make a file filled with random numbers only, this kind of file shouldn't compress anything at all if it's big enough.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Chevron.
Yeah, I've been having a few problems understanding a few of the Purebasics syntax's as Im completly new to the lang. I have got it sorted now and it is reporting 28k(not 168 bytes) for a 901k bitmap and its definately right as I deleted the original and the extracted the compressd file to verifiy.
Sorry to alarm you all
Yeah, I've been having a few problems understanding a few of the Purebasics syntax's as Im completly new to the lang. I have got it sorted now and it is reporting 28k(not 168 bytes) for a 901k bitmap and its definately right as I deleted the original and the extracted the compressd file to verifiy.
Sorry to alarm you all