How to read an archive on a background thread in a Tabris.js app

This is a follow-up on the previous blog post about “How to read an archive in a Tabris.js app“.

Today, we are going to use a Worker available in Tabris.js to read the content of an archive file. The Worker allows users to do heavy operations on a background thread without blocking the main (UI) thread. See the docs of the Worker for more information.

The zip file that we are going to read is available here. It has the following structure and contents:

├── a folder
│ └── message.txt (Hello world!)
└── another-message.txt (Hello earth!)

First, let’s prepare the Worker using a slightly modified snippet from the previous blog post:

The Worker will download and extract an archive file on a background thread after it’s done file paths, and their contents will be returned to the main thread. To keep it as simple as possible, we will just print the file paths and contents to the console.

That’s it!

The full code of the example is available here.

Fiddle with this example and run it in the Tabris.js developer app (Android/iOS) now:

Open in Gitpod