mockingbot / react-native-zip-archive

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

Convert a single file (.txt / .pdf / .xls) to a zip file from a specific path. #284

Closed vinayn-simelabs closed 10 months ago

vinayn-simelabs commented 1 year ago

Is there a way to convert a single file which can be any format say PDF, Txt, or Xls to a zip file using this plugin ? I've tried but it is showing "Cannot read proper zipFolder of null or zipFiles of null". I'm using RN fetch blob to create a PDF file.

let pdfLocation =
              Platform.OS == "ios"
                ? `${RNFetchBlob.fs.dirs.DocumentDir}/Barcode-labels.zip`
                : RNFetchBlob.fs.dirs.DownloadDir + "/Barcode-labels.zip";
            RNFetchBlob.fs.createFile(
              pdfLocation,
              res?.data?.data?.zebraCodeTxtFile,
              "base64"
            );
            console.log("Response: ", pdfLocation, res.data);

            zip(
              Platform.OS == "ios"
                ? [RNFetchBlob.fs.dirs.DocumentDir + "/"]
                : RNFetchBlob.fs.dirs.DownloadDir + "/",
              pdfLocation
            )
              .then((path) => {
                console.log(`zip completed at ${path}`);
              })
              .catch((error) => {
                console.error(error);
              })
plrthink commented 10 months ago

You should use zip(pdfLocation, dir) since the first argument is the zip not the target path.