arduino/Arduino · error · IOException

Error while extracting file {outputFile.getAbsolutePath()}

Error message

Error while extracting file {outputFile.getAbsolutePath()}

What it means

During extraction, copyStreamToFile throws this IOException when the archive input stream returns <= 0 bytes (EOF) while the entry still has bytes remaining to copy. It means the archive is truncated, corrupt, or the underlying stream was interrupted mid-entry.

Source

Thrown at arduino-core/src/cc/arduino/utils/ArchiveExtractor.java:294

    FileOutputStream fos = null;
    try {
      fos = new FileOutputStream(outputFile);
      // if size is not available, copy until EOF...
      if (size == -1) {
        byte buffer[] = new byte[4096];
        int length;
        while ((length = in.read(buffer)) != -1) {
          fos.write(buffer, 0, length);
        }
        return;
      }

      // ...else copy just the needed amount of bytes
      byte buffer[] = new byte[4096];
      while (size > 0) {
        int length = in.read(buffer);
        if (length <= 0) {
          throw new IOException("Error while extracting file " + outputFile.getAbsolutePath());
        }
        fos.write(buffer, 0, length);
        size -= length;
      }
    } finally {
      IOUtils.closeQuietly(fos);
    }
  }

}

View on GitHub (pinned to a0df6e0e83)

Solutions

  1. Verify the archive integrity (re-download or re-copy the file and check its checksum) and retry extraction
  2. Ensure the source stream/file is not being written or truncated concurrently while extracting
  3. Check that the archive is a valid zip/tar supported by the compressor used (correct compressionMethod)
  4. Free disk space if the volume filled up mid-extraction, then retry

Example fix

// before
downloader.downloadFile(url, archiveFile, false);
extractor.extract(archiveFile, outputDir);
// after: verify before extracting
if (archiveFile.length() < expectedMinSize) throw new IOException("archive truncated");
extractor.extract(archiveFile, outputDir);
Defensive patterns

Strategy: validation

Validate before calling

if (!archiveFile.exists() || archiveFile.length() == 0)
  throw new IllegalStateException("Archive missing/empty: " + archiveFile);
// optionally verify known checksum before extracting

Try / catch

try {
  extractor.extract(archive, dir);
} catch (IOException e) {
  if (e.getMessage().startsWith("Error while extracting file")) {
    // re-download the archive; it is truncated/corrupt
    reDownload(archive);
  } else throw e;
}

Prevention

When it happens

Trigger: extract() is copying a file entry of known size; in.read(buffer) returns -1 or 0 while size > 0, i.e. the stream ends before all expected bytes of the entry are read.

Common situations: Corrupted or partially downloaded archive file (e.g. failed library/platform download); archive modified or truncated during extraction; reading a compressed stream from a closed or failing source.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of arduino/Arduino@a0df6e0e83 (2026-09-06). Data as JSON: /api/errors/4ad7832d73887f82. Report an issue: GitHub.