Anfängerfragen zum Programmieren mit PureBasic.
jear
Beiträge: 288 Registriert: 17.10.2004 01:59
Wohnort: Ammerland
Beitrag
von jear » 11.02.2012 19:24
Warum bekomme ich beim UnpakMemory einen IMA?
Gibt es einen anderen Weg gepackte Texte einzubinden?
Code: Alles auswählen
#pak = 0
CompilerIf #pak
If CreateFile(1, "test.txt")
For ix = 1 To 20
WriteStringN(1, "Dies ist Text " + Str(ix))
Next
CloseFile(1)
EndIf
Debug "Len txt-file = " + Str(FileSize("test.txt"))
Delay(50)
CreatePack("test_txt.pak")
AddPackFile("Test.txt")
ClosePack()
Debug "Len pak-file = " + Str(FileSize("test_txt.pak"))
Debug "pak ratio = " + StrF(FileSize("test.txt") / FileSize("test_txt.pak"), 2)
End
CompilerElse
plen = ?lpIend - ?lpI : Debug "plen = " + Str(plen)
hdata = AllocateMemory(plen * 5) : Debug "hdata = " + Str(hdata)
ulen = UnpackMemory(?lpI, hdata) : Debug "ulen = " + Str(ulen) ; Error!
Debug PeekS(hdata, ulen, #PB_Ascii)
FreeMemory(hdata)
End
DataSection
lpI:
IncludeBinary "test_txt.pak"
lpIend:
EndDataSection
CompilerEndIf
Man ist nie zu alt zum lernen, auch wenn man dabei manchmal alt aussieht!
HeX0R
Beiträge: 3042 Registriert: 10.09.2004 09:59
Computerausstattung: AMD Ryzen 7 5800X 96Gig Ram NVIDIA GEFORCE RTX 3060TI/8Gig Win11 64Bit G19 Tastatur 2x 24" + 1x27" Monitore Glorious O Wireless Maus PB 3.x-PB 6.x Oculus Quest 2 + 3
Kontaktdaten:
Beitrag
von HeX0R » 11.02.2012 22:15
UnpackMemory ist nicht kompatibel zu AddPackFile().
Entweder packst du das File per PackMemory() und schreibst den gepackten Memory per WriteData() in eine Datei, oder du entpackst eine
via AddPackFile() erstellte Datei per OpenPack() und NextPackFile().
jear
Beiträge: 288 Registriert: 17.10.2004 01:59
Wohnort: Ammerland
Beitrag
von jear » 12.02.2012 00:47
HeX0R hat geschrieben: UnpackMemory ist nicht kompatibel zu AddPackFile().
Entweder packst du das File per PackMemory() und schreibst den gepackten Memory per WriteData() in eine Datei, oder du entpackst eine
via AddPackFile() erstellte Datei per OpenPack() und NextPackFile().
Danke HeXOR, das war's
Code: Alles auswählen
#pak = 0
CompilerIf #pak = 0
If CreateFile(1, "test.txt")
For ix = 1 To 20
WriteStringN(1, "Dies ist Text " + Str(ix))
Next
CloseFile(1)
EndIf
Debug "Len txt-file = " + Str(FileSize("test.txt"))
Delay(50)
If ReadFile(1, "test.txt")
ulen = Lof(1) : Debug ulen
*udata = AllocateMemory(ulen)
ReadData(1, *udata, ulen) : CloseFile(1)
*pdata = AllocateMemory(ulen)
plen = PackMemory(*udata, *pdata, ulen) : Debug plen
CreateFile(1, "test_txt.pak")
WriteData(1, *pdata, plen) : CloseFile(1)
EndIf
FreeMemory(*udata) : FreeMemory(*pdata)
Debug "Len pak-file = " + Str(FileSize("test_txt.pak"))
Debug "pak ratio = " + StrF(FileSize("test.txt") / FileSize("test_txt.pak"), 2)
End
CompilerElse
plen = ?lpIend - ?lpI : Debug "plen = " + Str(plen)
*pdata = AllocateMemory(plen * 5) : Debug "pdata = " + Str(*pdata)
ulen = UnpackMemory(?lpI, *pdata) : Debug "ulen = " + Str(ulen)
Debug PeekS(*pdata, ulen, #PB_Ascii)
FreeMemory(*pdata)
End
DataSection
lpI:
IncludeBinary "test_txt.pak"
lpIend:
EndDataSection
CompilerEndIf
Man ist nie zu alt zum lernen, auch wenn man dabei manchmal alt aussieht!