Skip to content

Size file parts from the IO before falling back to its path - #111

Draft
wtn wants to merge 1 commit into
socketry:mainfrom
wtn:path
Draft

wtn wants to merge 1 commit into
socketry:mainfrom
wtn:path

Conversation

@wtn

@wtn wtn commented Oct 26, 2026 •

Copy link
Copy Markdown

Fixes #23, fixes #110.

FilePart sized an IO without #length with File.size(io.local_path). That raised ENOENT ... local.path for IOs with #size but no path, such as Down::ChunkedIO (#110), and NoMethodError for objects passed without UploadIO, such as Rails' ActionDispatch::Http::UploadedFile. It also measured the wrong file when the path no longer led to the open one: deleted after opening, relative after a Dir.chdir, or Tempfile.create(anonymous: true).

FilePart now uses #length, then #size, then the file at local_path, and raises ArgumentError when none gives a length, e.g. a Down::ChunkedIO without a Content-Length.

UploadIO now opens a Pathname as a filename. Pathname responds to #read, but Pathname#read(length) always reads from the start of the file, so with #size in use its uploads would never end.

For Down users: with a gzip-encoded response, ChunkedIO#size is the compressed length. Passing headers: { "Accept-Encoding" => "identity" } to Down.open avoids this.

Types of Changes

  • Bug fix.

Contribution

@wtn
wtn force-pushed the path branch 6 times, most recently from 23787ff to 9e22a6d Compare October 26, 2026 20:50

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recognize #size on an IO, not just #length? Errno::ENOENT: No such file or directory - local.path

1 participant