Jump to content

Memory after decode


Oleg2339798

Recommended Posts

Hi, when i use this code Lua memory shows about 76mb, while file is just 33

Code:

  
    local open = fileOpen(name) 
    local readbyte = fileRead( open, fileGetSize ( open )) 
    local k = base64Decode(teaDecode( readbyte, Pass )) 
    local f = fileCreate("temp")  
    fileWrite(f, k) 
    fileClose(f) 
    k=nil 
    readbyte=nil 
    fileClose(open) 
    fileDelete("temp") 
  

Where could be the problem?

Link to comment

This is caused by the way Lua strings are represented in memory.

To be able to deal with big files, you have to split them into small chunks as follows:

local file = fileOpen("bigfile.dat") 
local size = fileGetSize(file) 
  
-- Get number of chunks needed (50 KB chunk size) 
local chunkSize = 50000 
local numChunks = math.ceil(size / chunkSize) 
  
-- Read until the end is reached 
while not fileIsEOF(file) do 
    local readBytes = fileRead(file, chunkSize) 
    local decrypted = base64Decode(teaDecode(readBytes , Pass)) 
    fileWrite(otherFile, decrypted) 
end 

You have to split the base64Encode and teaEncode calls on the input files as well though.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...