Jump to content




Compression


  • This topic is locked This topic is locked
5 replies to this topic

#1 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 09 February 2013 - 03:43 PM

i would like how to compress programs, npaintpro images and random files so i can make 1 file for all and make that file 3 or 4 times smaller than the original files, any ideas?

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 09 February 2013 - 04:04 PM

Perhaps you could save the text of all of the files as multiline strings in one program?

local programs = {
  program1 = [[
print 'Hello World!'
  ]];

  program2 = [[
print 'This is another program!'
  ]];
}

And then pairs() through them all and write them accordingly.

for programName, content in pairs(programs) do
  local file = fs.open(programName, 'w')
  file.write(content)
  file.close()
end

Though there's probably a better, and more automatic way to do this. I believe some people around here have made some compression programs.

#3 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 09 February 2013 - 04:14 PM

for saving all files in a one file the code is this:

file = fs.open("files", "r")
b = {}
while true do
  d = file.readLine() 
  c = fs.open(d, "r")
  if not d then break end
   a = c.readAll()
  b[d] = a
end
file.close()
file = fs.open("output", "w")
file.write(textutils.serialize(B)/>
file.close()
the file is like:
file.1lol
file2.pr
file5.nfa
etc
and the output:
{["file.1lol"] = content, etc
and the result will only have one line(if you dont count the part for reading it so it can be runned), but i want to compress that so it gets like 4 times less that the original output, its possible?

#4 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 09 February 2013 - 04:43 PM

The only way I know of would be to run through the string, and shorten any frequently used keywords, like "function" or "local" to something like "@f" or "@l", a unique identifier that isn't available in regular lua syntax so nothing is mixed up. Then, on rewriting the programs, replace the shortenings with their original keywords.

I've only scraped the surface of actual compression, however, so I'm positive there's a better way to do that.

#5 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 09 February 2013 - 05:21 PM

I have crreated a program that compress files check it out

#6 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 09 February 2013 - 05:49 PM

Locked as requested.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users