Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Handle/create Tar or similar package in gideros? - Gideros Forum

Handle/create Tar or similar package in gideros?

piepie Member
edited August 27 in General questions
Hi, I would need to create some packages containing ogg files and a json file in a single package file to expand an app "on demand" and easily share those packages between users. Uncompressed tar-like I think should be enough: do you think it's possible with gideros? How?

Thank you


P.S. Here is the updated working project for anyone who may need it
zip
zip
filepacker.zip
19K

Comments

  • check
    http://lua-users.org/wiki/CompressionAndArchiving
    probably you are better off with zipping.

    http://docs.giderosmobile.com/reference/lua/zlib#zlib
    the native gideros zip cannot handle multiple files? worst case scenario you can append them after each other and zip that with zlib and put the append-info in front of this file.

    Likes: pie, antix, Apollo14

    +1 -1 (+3 / -0 ) Share on Facebook
  • piepie Member
    @keszegh thank you, may you elaborate a little more on how to merge all files together and retrieve those (unmerge) when needed?

    I actually don't need to do it on the run, it may also take a while since it's something that a user does once per package.
    The files I need to merge are ogg and json, if that makes a difference.
    I don't think there is much room for compression in ogg files, that's why I thought about uncompressed tar, the goal would be to share those packages easily between users / upload and download them as single files.

    Thank you :)
  • keszeghkeszegh Member
    edited August 26
    actually you may be able to cheat and use one table saved in json which contains names and strings, each of them is a filename and a file.
    you need to require json and do something like:
    function loadFile(path)
    local file = io.open( path, "r" )
    if file then
       local contents = file:read( "*a" )
       io.close( file )	
       return contents
    end
    end
     
    data={}
    data[filename]={}
    data[file]={}
    data.filename[1]="mus.ogg"
    data.file[1]=loadFile("|R|mus.ogg")
    data.filename[2]="level1.json"
    data.file[2]=loadFile("|R|level1.json")
     
    local path="|D|fulldata.metajson"
    local jsonString = json.encode( data )
    local file = io.open( path, "w" )
    if file then
       file:write( jsonString )
       io.close( file )
    end
    i did not test it but probably you get the idea. and probaby using json.decode and saving to file you can do the 'unzipping' part along these lines too.

    Likes: Apollo14, pie

    +1 -1 (+2 / -0 ) Share on Facebook
  • keszeghkeszegh Member
    edited August 26
    and as you can see i did not zip anything, so it is just storing. if you want to decrease size then at the end the jsonString needs to be zipped with the zip plugin of gideros before saving it to file.

    Likes: Apollo14, pie

    +1 -1 (+2 / -0 ) Share on Facebook
  • piepie Member
    Thank you @keszegh it almost works, at least to a certain extent: :s
    I think I have some issues with character encoding because in my unpack function I get this error:

    Expected value but found invalid token at character 1

    I remember this one from 2015 http://giderosmobile.com/forum/discussion/comment/39973/#Comment_39973 but in this case even converting the file as UTF-8 without BOM with notepad++ returns that error.

    Do you or anyone else have some ideas about it?
    Attached you can find my pack and unpack functions to make your tests if you have some time.

    Thank you :)
  • antixantix Member
    edited August 26
    @Pie do you have an actual example that causes the issue? I'm wondering if the issue is not how you are loading your saved compressed file. You should be using the binary open arg..
    local file = io.open( path, "rb" )
    If you jusrt use 'r' then it might not be reading the entire file. In my ARPG I load all hero files at the game start and each one is encrypted, then encoded to MIME64 and then zlib compressed..
    function HeroManager:loadHero(name)
      local file = io.open("|D|heroes/" .. name, "rb")
      local compressed = file:read("*all") -- load compressed file
      local encrypted = zlib.decompress(compressed, 15) -- decompress file
      local jsonString = ACRYPT:decrypt(encrypted) -- decode/decrypt to json string
      local hero = json.decode(jsonString) -- recreate table from json string
      file:close()
      return hero
    end
  • piepie Member
    good point @antix but I can't get it to work either.. :/
    I put together a project that should pack a bunch of pngs, please let me know if you spot something strange here.

    Thank you :)

  • keszeghkeszegh Member
    edited August 26 Accepted Answer
    there is only one slight error, you run json.decode for the filenames and not the loaded file data, so change line 68 to:
    data = json.decode( loadFile(source_file ))
    (and make loadFile function reachable to depack function).
  • piepie Member
    edited August 26
    of course! :o Thank you very much @keszegh :)

    working project attached on the first post.

    +1 -1 (+3 / -0 ) Share on Facebook
Sign In or Register to comment.