How to retrieve a packed string? [SOLVED]

Everything else that doesn't fall into one of the other PB categories.
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

How to retrieve a packed string? [SOLVED]

Post by SkyManager »

I run this test

Code: Select all

src = "This is a testing line string.This is a testing line string.This is a testing line string.This is a testing line string.This is a testing line string."
srcLen  = Len(src)
*srcMem = AllocateMemory(srcLen + 1)
*destMem= AllocateMemory(srcLen+100)
PokeS(*srcMem, src)
res = PackMemory(*srcMem, *destMem, srcLen)
debug src
debug "Pack Result = " + Str(res)
debug "Packed String = " + PeekS(*destMem)
and returns the packed string is

Code: Select all

JC:
How can I obtain the resulting packed string :?:
Last edited by SkyManager on Sun Mar 04, 2007 5:32 pm, edited 1 time in total.
dige
Addict
Addict
Posts: 1417
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

The packed memory is'nt a string anymore! They are raw data which can
contains zero bytes as well ... but zero is defined as string termination.

If you need packed data as string, you can use the masking procedure
from my en/decrytion code...

http://www.purebasic.fr/english/viewtopic.php?t=25560

-> DG_MemoryToStr ( *source, ssize ) ; Convert Memory to String
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post by SkyManager »

Does the standard PeekS() can retrieve memory raw data and converts to a string :?:
dige
Addict
Addict
Posts: 1417
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

No, it collects only all chars up to the next #Null Byte.
For example:

Data in Memory: 50 55 52 45 00 42 41 53 49 43

PeekS() will read the read the first 4 chars -> "PURE"
instead of "PURE BASIC"
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post by SkyManager »

Thanks for the explanation and your routine. :cry:
My question is :
After I use the packer function to pack/compress something, I need to collect the result of the packing and store it somewhere. How can I do that?
Post Reply