This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
nitrogenfingers's profile picture

Compress/Extract- Convert Directories to Files

Started by nitrogenfingers, 03 January 2013 - 07:44 PM
nitrogenfingers #1
Posted 03 January 2013 - 08:44 PM
I'm at a point with some of my programs where I have to upload 5 or 6 or more files to pastebin for them all to work together cohesively. This gets boring fast, so I wrote this app for larger projects to be easily send up and down again.

The compressor essentially takes and recursively parses through a directory, putting the contents of each file inside into a much larger text file. The process is then reversed by the extractor, preserving every file and the directory structure within.

It has a few problems. Firstly it doesn't decrease the file size at all, in fact it's quite a bit larger. I'm not sure if pastebin allows upload of binary files but if it does I'll look at adding huffman coding. Secondly, I've noticed io will time out on large files if you're running on a slow computer. Beware of this, not sure of a fix.

Anyway you can get it here:

Extractor: http://pastebin.com/461hnYHf
Compressor: http://pastebin.com/9PcVRBy6

And here's an example of what a compressed file will look like. It's basically a set of instructions to recreate the file- if I get around to it I'll try to make the archives self-extracting:
Spoiler


MKDIR gunshot
MKDIR gunshot/artwork
MKFIL gunshot/artwork/cowstill.nfp
WRITE 10

 cc   
cccc  
 66   
 666  
 dd   
 dd   
 76   
 cc   
 ccc  
MKFIL gunshot/artwork/shrub.nfp
WRITE 3
5 5
 5

MKFIL gunshot/gunshot
WRITE 2
print("Gunshot the game")
print("Coming soon!")
MKFIL gunshot/readme.txt
WRITE 3
Gunshot is a game that will be coming out soon!
I guarantee it'll be okayish at least, awesome at best.
Stay tuned...

Hope someone finds it useful.

NF
theoriginalbit #2
Posted 03 January 2013 - 10:26 PM
Good job! Was thinking if eventually tinkering with this in the future. Was not looking forward to having to work out compression and self extraction.

I'm going to keep an eye on this post, hope you get the compression part done, coz that would be awesome!
wilcomega #3
Posted 04 January 2013 - 02:06 AM
i could make an installer for this :D/> so when you execute it it will be installing the files from the installer file
Mendax #4
Posted 04 January 2013 - 03:57 PM
Perfect! Just what I needed for SKS-OS! (Around 20 files now…)
kornichen #5
Posted 05 January 2013 - 12:18 AM
Can I use it for KREOS? (45 files at the moment :D/>)?
nitrogenfingers #6
Posted 05 January 2013 - 12:50 AM
I should make this more official, but really if I've put a program on the forums you can use it for about whatever- but let me see what you've done with it, if you'd be so kind :D/>
billysback #7
Posted 05 January 2013 - 12:57 AM
Nitro, for the fix on making it not bug out on large files you must make it sleep every now and again on the file writing - or reading - loop, making it sleep every time is unnecessary so add in some type of tick, the amount of times it must tick before you sleep depends on how much you are doing in the loop, in my experience it crashes at between 500 and 700 lines when almost only writing files.

look at this if you want:
Spoiler

print("Writing to output...")
    
    local tx,ty = term.getSize()
    
    local erase = ""
    for i=1,tx do erase = erase.." " end
    
    local x,y = term.getCursorPos()
    
    if tn == -2 then
        print("Aprox. "..(0.005*#outlines).." seconds...")
    end
    for i=1,#outlines do
        local line = outlines[i]
        if line ~= nil and string.len(line) > 0 then
            output.writeLine(outlines[i])
        end
        
        local p = math.floor(tonumber((i/#outlines)*100))
        if tn ~= nil and tn > -2 then
            term.setCursorPos(x, y)
            term.write(erase)
            term.setCursorPos(x, y)
            term.write("%"..p.." done!")
        end
        if tn ~= nil and tn > -1 then
            sleep(tn)
        end
    end
    print("")
    output.close()
tn is a number signifying which type of loop to do.
this is sort of messy, but whatever.