Decompression of zip with audio files - jszip and jszip-utils

I am Using SDK 35 on Android and IOS.

I have managerd tro download zip file using the expo’s FileSystem.
Then by using this this crna-zipfile/App.js at master · smoll/crna-zipfile · GitHub
I managed to decompress and save individual files in IOS.

 async downloadZipFile() {
    const localUri = `${FileSystem.documentDirectory}files.zip`
    console.log('zip uri', localUri)
    const remoteUrl = 'https://raw.githubusercontent.com/smoll/crna-zipfile/master/remote/files.zip'
    const {uri} = await FileSystem.downloadAsync(remoteUrl, localUri)
    console.log('Finished downloading to ', uri)

    const data = await new JSZip.external.Promise((resolve, reject) => {
      JSZipUtils.getBinaryContent(uri, (err, data) => {
        if (err) {
          reject(err)
        } else {
          resolve(data)
        }
      })
    })

    const zip = await JSZip.loadAsync(data)
    zip.forEach(async (relativePath, file) => {
      console.log('file: ', file)
      console.log('relativePath: ', relativePath)

        const content = await file.async('binarystring')
        console.log('content: ', content)

        const tmp = relativePath.split('.')
        const basename = tmp[0]
        const ext = tmp.slice(-1)[0]
        const unzipped = `${FileSystem.documentDirectory}${basename}-unzipped.${ext}`
        await FileSystem.writeAsStringAsync(unzipped, content)
        console.log('unzipped: ', unzipped)
        const text = await FileSystem.readAsStringAsync(unzipped)
        this.setState({text})
      
    })
  }

The problem is that in Android const content = await file.async(‘binarystring’) returns empty.

Well the

JSZipUtils.getBinaryContent

is actually making an XMLHttpRequest() with the file path of the form file:///…
It seems that in android that is not doable or I might miss something.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.