0

I'm trying to convert an existing CSV file to a gzip file.

I verified the CSV looks good. Once I run this code, I get a "failed to expand" error and tried an online decompression tool that also failed, so it seems the output zip is corrupt.

    public void compressGzip(String input, String dest) throws IOException {

        Path pathSource = Paths.get(input);
        Path destSource = Paths.get(dest);

        try (GZIPOutputStream gos = new GZIPOutputStream(
                new FileOutputStream(destSource.toFile()));
             FileInputStream fis = new FileInputStream(pathSource.toFile())) {

            byte[] buffer = new byte[1024];
            int len;
            while ((len = fis.read(buffer)) > 0) {
                gos.write(buffer, 0, len);
            }

        }
    }

enter image description here

Anything I could be missing here?

Ryan
  • 1,102
  • 1
  • 15
  • 30
  • The while loop hits one iteration – Ryan Sep 25 '21 at 03:36
  • You're code works okay for me – MadProgrammer Sep 25 '21 at 03:45
  • @MadProgrammer any chance /tmp directory would affect this at all ? Mac OS – Ryan Sep 25 '21 at 03:49
  • @Ryan No idea, I'm running on MacOS as well, trying to find a large file – MadProgrammer Sep 25 '21 at 03:50
  • @Ryan Yes, maybe try expanding into a more public space. I zip a 36mb video file and had no issue decompressing it (using my Downloads folder) – MadProgrammer Sep 25 '21 at 03:54
  • Interesting. I'm testing with a small file (1KB). Surprised it's not working. I have a single mount point on my k8s cluster underneath /tmp so a bit tied down with this path when I deploy – Ryan Sep 25 '21 at 03:57
  • 2
    Just curious, and not sure it matters, but if you're using GZIP streams, why does your destination file have a `.zip` extension? Shouldn't it be `.gz`? – Slaw Sep 25 '21 at 04:05
  • I agree with slaw. I was just about to suggest the same. Rename the file to .gz and try to open it. Also try to open with a other utility like 7zip. – Atmas Sep 25 '21 at 04:08
  • gz extension didn't make a difference – Ryan Sep 25 '21 at 05:06

0 Answers0