mockingbot / react-native-zip-archive

Zip archive utility for react-native
MIT License
420 stars 154 forks source link

Unzip file with expo #297

Closed RobinAlonzo closed 1 month ago

RobinAlonzo commented 9 months ago

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();
Abdullah-Mazumder commented 8 months ago

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

oiver555 commented 6 months ago

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

wahidshadab commented 6 months ago

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

Abdullah-Mazumder commented 6 months ago

@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

7ammer commented 3 months ago

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

plrthink commented 3 months ago

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.

ShaneZhengNZ commented 2 months ago

@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.

plrthink commented 1 month ago

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