react-native-zip-archive icon indicating copy to clipboard operation
react-native-zip-archive copied to clipboard

Unzip file with expo

Open RobinAlonzo opened this issue 1 year ago • 7 comments

I use expo to run my IOS and Android applications. I want to use the react-native-zip-archive lib but as soon as I try to run my code I get this error

[TypeError: Cannot read property 'unzip' of null]

Does anyone have a solution?

const downloadAndExtractZip = async () => {
  try {
    // Définition des variables
    const zipUrl = "URL_DU_SITE";
    const fileUri = FileSystem.documentDirectory + "Chupaca.zip";
    const destinationDirectory = FileSystem.documentDirectory + 'maps/';
    const charset = "UTF-8";

    // Vérification de l'existence du fichier ZIP
    const fileInfo = await FileSystem.getInfoAsync(fileUri);

    if (fileInfo.exists) {
      const files = await FileSystem.readDirectoryAsync(FileSystem.documentDirectory);
      console.log('Contenu du répertoire :', files);
    }

    // Téléchargement du fichier ZIP
    const downloadFile = await FileSystem.downloadAsync(zipUrl, fileUri);

    if (downloadFile.status === 200) {
      console.log('Téléchargement du fichier ZIP terminé.')

      // Extraction du fichier ZIP
      console.log('Extraction du fichier ZIP...' + fileUri)
      await unzip(fileUri, destinationDirectory, charset)
      console.log('Extraction du ZIP terminée.');
    } else {
      console.log('Erreur lors du téléchargement du fichier ZIP.');
    }
  } catch (error) {
    console.error('Erreur lors de la récupération du fichier ZIP :', error);
  }
  ;
};

// Utilisation de la fonction pour télécharger et extraire le fichier ZIP
downloadAndExtractZip();

RobinAlonzo avatar Nov 18 '23 11:11 RobinAlonzo

Do you have the solution? I am also getting the same problem..... @plrthink is there any solution for expo?

Abdullah-Mazumder avatar Jan 05 '24 15:01 Abdullah-Mazumder

Guys you have to npx expo install this library to ensure expo obtains the compatible version for your project and then build it using the eas-cli since this is not a part of the Expo library it will not work with Expo apps on the fly. What you need to do is search up how to build custom dev clients with expo and your problem will be solved. @Abdullah-Mazumder @RobinAlonzo

oiver555 avatar Feb 25 '24 20:02 oiver555

@plrthink, @Abdullah-Mazumder Have you found any solutions to it?

wahidshadab avatar Mar 01 '24 16:03 wahidshadab

@plrthink, @Abdullah-Mazumder Have you found any solutions to it?

Yes. You have to use development build to test your app.expo go will not work with this package

Abdullah-Mazumder avatar Mar 01 '24 16:03 Abdullah-Mazumder

This issue should be closed if the above solves the issue. It's not going to work on Expo Go.

7ammer avatar Jun 04 '24 11:06 7ammer

Since expo is recommended by the react-native team, its support should be prioritized more highly. But I'm not familiar with it and don't have enough time, so I'm hoping someone could take this on.

plrthink avatar Jun 05 '24 23:06 plrthink

@plrthink Nothing you need to do. This package works perfectly with Expo Dev Client. We have been using this for over a year now. No problems at all.

As the other guys pointed out, the package just won't work with Expo Go.

ShaneZhengNZ avatar Jun 13 '24 22:06 ShaneZhengNZ

Thanks for point out, I mean I need to mention this in the README at least.

plrthink avatar Aug 09 '24 08:08 plrthink