Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Will it make sense to pack multiple files together? How? — Gideros Forum

Will it make sense to pack multiple files together? How?

Hi,
my question rises from a thought I had about my app:

I'd like to add a lot of sound files (around 5000, but they could be more) and I am worried that I would eventually reach some maximum number of files allowed cap: see here https://stackoverflow.com/a/2652238/20463613

My first thought was to split them in subdirectories, but I wonder if there is a better way to handle that which might even be of easier maintenance for the future and "download friendly".

If I could "pack" like tarball my sound files I will have to handle only one "soundpack" file, and I could easily have this single file available as "additional downloadable content" for the users who are running low on storage space. (my app is less than 10mb, but with sounds it goes up to 50mb and counting).

Unfortunately my knowledge stops here:
Do you think it's worth thinking about this potential issue or I am just being too much pessimistic? :)

If I am making sense: how could I build a pack of files, keeping an index, so that when my app needs "SOUND00345" it can read directly this sound from the soundpack file based on its index? I guess that this is almost the same that the filesystem does, so maybe I am just thinking about redoing something that already is taken care of.. :#

I've found an untar pure lua library here: https://github.com/mimetic/tar.lua which works fine in gideros, but the only way to extract a single file from the archive is to parse it all until it finds the file/files inside the archive, and this might be counterproductive if the archive is big because it certainly takes time..

Any idea/suggestion is appreciated

Thank you :)

Comments

  • hi pie :) , imho you are overthinking it :p
    5000 sound files for 50mb imho this should be expected and people won't find this unacceptable?
    + Android storage are quite large nowadays.

    Likes: pie

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    If you really think it is worth, you can just concat all your sound files together, and build table referencing the start and length of each one within the big archive. You could eventually append that table (as json maybe) after the sound files, and then append the size of the table as four bytes word, to have a single file to download or process.

    To use it afterwise in Gideros, load the last four bytes of your file and decode them to get the size of your index table, then extract the index table using its size, decode it and lookup the offset/size of your audio file with it. Then use a Buffer loaded with the audio file data to play it.

    Likes: pie

    +1 -1 (+1 / -0 )Share on Facebook
  • piepie Member
    @MoKaLux maybe you're right and I am overthinking it, but I think that a small app have much more appeal to users and google play store vs a bigger one.

    I am not yet sure if it's worth the hassle but I tried to follow @hgy29 suggestion as an exercise because there is a lot to learn there for me:
    I managed to achieve the concatenation of files and the retrieval from the packed file, but I am missing a point here:
    hgy29 said:

    append the size of the table as four bytes word

    I apologize for my ignorance; how to convert an integer to 4 bytes and transform these bytes back?
    My google searches couldn't help: I can never get the starting integer back, instead I get bigger numbers and everything goes south... :disappointed:

    Thank you :)

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited August 2023
    pie allow me to persist, there is a saying in my culture which says:
    "If you have the choice between 2 things, pick the easiest one"

    ;)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • hgy29hgy29 Maintainer
    edited August 2023 Accepted Answer
    You can use string.encodeValue(value, "I") to turn an integer into a four byte string, and string.decodeValue(string,"I") to do the opposite

    EDIT: since luau, you can use string.pack and string.unpack too. https://www.lua.org/manual/5.3/manual.html#6.4.2

    Likes: pie

    +1 -1 (+1 / -0 )Share on Facebook
  • piepie Member
    Thank you @hgy29 , I tried those yesterday but I had weird results: now it's working :| maybe I just needed a reboot :smile:
    string.encodeValue/decodeValue is not documented anywhere though, I've found it only in a post of yours inside the 80's style demos. Is it a gideros' special?
    MoKaLux said:


    "If you have the choice between 2 things, pick the easiest one"

    I may still choose the easiest route, but I have a choice now that I didn't have yesterday, and I've learned something in between: "those who never try are sure to fail".

    :smile:

    Thank you again!

    Likes: MoKaLux, hgy29

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