Пригласили на Discord, где есть масса кодеров. Сегодня начали обсуждать способ сжатия скрипта. Оказывается, сжатие реализовано в версии 0.80(и наконец-то она работает в w7 32бит).
Сжатие(Python3)
import sys
import zlib
name = "sounds.txt"
with open(name, mode='rb') as file:
uncomp = file.read()
print("Uncompressed length: {} bytes".format(len(uncomp)))
comp = zlib.compress(uncomp)
print("Compressed length: {} bytes".format(len(comp)))
print("With header: {} bytes".format(len(comp)+4))
with open(name+".tic", 'wb') as file:
file.write(bytes([16]))
file.write(bytes([len(comp) & 0xFF]))
file.write(bytes([len(comp) >> 8]))
file.write(bytes([0]))
file.write(comp)
import zlib
name = "sounds.txt"
with open(name, mode='rb') as file:
uncomp = file.read()
print("Uncompressed length: {} bytes".format(len(uncomp)))
comp = zlib.compress(uncomp)
print("Compressed length: {} bytes".format(len(comp)))
print("With header: {} bytes".format(len(comp)+4))
with open(name+".tic", 'wb') as file:
file.write(bytes([16]))
file.write(bytes([len(comp) & 0xFF]))
file.write(bytes([len(comp) >> 8]))
file.write(bytes([0]))
file.write(comp)
На PureBasic:
OpenLibrary(0, "zlib1.dll")
file$ = "cir.lua"
ReadFile(0, file$)
SourceLen = Lof(0)
*SourceMem= AllocateMemory(SourceLen)
ReadData(0, *SourceMem,SourceLen)
CloseFile(0)
;calculate buffer, allocate memory and compress
DestLen = ((Sourcelen +(((Sourcelen)/1000)+1)+12))
*DestMem=AllocateMemory(DestLen)
result = CallCFunction(0, "compress", *DestMem, @DestLen, *SourceMem, SourceLen)
;write compressed memory to file
If result = 0
CreateFile(1, "cir.tic")
WriteAsciiCharacter(1,16)
WriteWord(1,DestLen)
WriteAsciiCharacter(1,0)
WriteData(1, *DestMem, DestLen)
;WriteAsciiCharacter(1,0)
CloseFile(1)
EndIf
CloseLibrary(0)
file$ = "cir.lua"
ReadFile(0, file$)
SourceLen = Lof(0)
*SourceMem= AllocateMemory(SourceLen)
ReadData(0, *SourceMem,SourceLen)
CloseFile(0)
;calculate buffer, allocate memory and compress
DestLen = ((Sourcelen +(((Sourcelen)/1000)+1)+12))
*DestMem=AllocateMemory(DestLen)
result = CallCFunction(0, "compress", *DestMem, @DestLen, *SourceMem, SourceLen)
;write compressed memory to file
If result = 0
CreateFile(1, "cir.tic")
WriteAsciiCharacter(1,16)
WriteWord(1,DestLen)
WriteAsciiCharacter(1,0)
WriteData(1, *DestMem, DestLen)
;WriteAsciiCharacter(1,0)
CloseFile(1)
EndIf
CloseLibrary(0)
Комментарии
Отправить комментарий