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

can't unzip no one file

Open chiefchief opened this issue 5 years ago • 7 comments

first of all i tried download file via rn-fetch-blob, and unzip got path - Couldn't open file then i locally place file in correct directory and same issue - Couldn't open file tried different zip files and every time same issue

via rn-fetch-blob

RNFetchBlob.config({
	fileCache: true,
	path: DocumentDirectoryPath + '/my.zip',
})
	.fetch('GET', 'https://file-examples-com.github.io/uploads/2017/02/zip_5MB.zip')
	.then(res => {
		const targetPath = DocumentDirectoryPath
		unzip(res.path(), targetPath)
			.then(path => {
				console.log(`unzip completed at ${path}`)
			})
			.catch(error => {
				console.error(error)
			})
	})

place file locally into directory and got - Failed to extract file error in opening zip file

const filePath = `${DocumentDirectoryPath}/my.zip`;
const targetPath = DocumentDirectoryPath;

unzip(filePath, targetPath)
    .then(path => {
        console.log(`unzip completed at ${path}`)
    })
    .catch(error => {
        console.error(error)
    })
})

chiefchief avatar Jul 30 '20 07:07 chiefchief

+1

n0umankhan avatar Aug 07 '20 15:08 n0umankhan

any update on this seems like package is broken ? @plrthink

n0umankhan avatar Aug 07 '20 16:08 n0umankhan

@chiefchief Can you place the file you're working with? It's hard to tell what's wrong with your code since it's working on my side.

plrthink avatar Aug 17 '20 13:08 plrthink

@chiefchief there could be few reasons i.e 1 - path is incorrect 2 - zip file is broken

in my case my path was wrong i created a utility for myself, see if you can use it:

export const unzipMethod = (slug) => {
  RNFS.mkdir(`${RNFS.DocumentDirectoryPath}/${slug}`).then(() => {
    const sourcePath = `${RNFS.DocumentDirectoryPath}/${slug}.zip`;
    const targetPath = `${RNFS.DocumentDirectoryPath}/${slug}/`;

    unzip(sourcePath, targetPath)
      .then(() => {
        console.log('unzipped');
        RNFS.unlink(`${RNFS.DocumentDirectoryPath}/${slug}.zip`);
      })
      .catch((error) => {
        console.log(error);
      });
  });
};

slug in my case is the name of zip file and the folder name i want to create, just remember to add "/" at the last in target path it will make sure to unzip under the folder

n0umankhan avatar Aug 17 '20 14:08 n0umankhan

I'm not sure if this is the same problem, but I can't unzip anything either. Autolinking isn't working — I get TypeError: null is not an object (evaluating 'RNZipArchive.unzip'). Any ideas? I'm using Expo but didn't have much luck with straight React Native either.

elon-gs avatar Sep 01 '20 13:09 elon-gs

@elon-gs I'm happy to help you if you can provide a minimal reproducible repo.

plrthink avatar Sep 01 '20 14:09 plrthink

my file is save but i unable to where is the file will save?????

yavnaveen avatar Mar 09 '23 09:03 yavnaveen