Zip plugin logic

I’m unzipping epub file with zip.uncompress(), what I’ve inspected:

  1. dstBaseDir - can be only system.* (e.g. system.CachesDirectory) - guess it should be mentioned in documentation.
  2. You can’t access files after zip.uncompress( zipOptions ) in your code, because it has strange implementation. There is option to access files inside listener, BUT you can’t modify. So I guess I could just use multithreading, but sadly listener is executing in hidden thread, which you can’t wait for in your code.

My main question is how to modify unzipped files using this plugin?
And minor question is where to find source code of this plugin?

Hi! Is that what you’re looking for?

About how to modify, I haven’t used it myself but I don’t think modifying files are in the scope of this plugin. I think you should look into these pages from the docs → Solar2D Documentation — Developer Guides

Looking at the example code from the docs, you may be able to use the listener to assign those files into variables, modify them and re-compress the files from those variables. Like I said, I haven’t used it myself but that seems like a way to do it. If you can upload a small, sample code we can look into that.

Thanks for your answer, ty for sources. I’ll try the assigning files to variable. The code I will upload to github soon, then I will reveal here the part of interest

Code is here GitHub - FirowMD/epub-reader: Epub reader powered by Solar2D.
File modules/epub.lua, function:

local function unzipEpub( filePath )
    print( "Unzipping...", filePath )

    local zipOptions = {
        zipFile = filePath,
        zipBaseDir = system.CachesDirectory,
        dstBaseDir = system.CachesDirectory,
        listener = function( event )
            if event.isError then
                native.showAlert( "Error", "Unzip error", { "OK" } )
            end
        end
    }

    zip.uncompress( zipOptions )
end

The only way to work with unarchived files is to insert code inside listener but it’s not my case, I just want to put some semaphore or just wait for that idk. Think I’ll just replace built-in zip library with another.

1 Like