Skip to content

feat(core): stream a container file into a binary destination - #1152

Open
archit15singh wants to merge 1 commit into
testcontainers:mainfrom
archit15singh:feat/copy-file-stream
Open

archit15singh wants to merge 1 commit into
testcontainers:mainfrom
archit15singh:feat/copy-file-stream

Conversation

@archit15singh

Copy link
Copy Markdown

Fixes #1149. A caller can now copy one regular file into an open binary stream, including a BytesIO or a network writer, without creating a temporary file.

with io.BytesIO() as output:
    container.copy_file_from_container_to("/tmp/result.bin", output)
    data = output.getvalue()

The transfer reads Docker's tar stream incrementally, handles short writes, and leaves the destination open. The existing path-based copy method is unchanged.

I tested a 4 MiB binary file against Docker Engine 28.5.2. The destination received multiple bounded writes with the expected SHA-256. The suite also checks that the first write occurs before all input has arrived and that a directory is rejected. Ryuk was disabled for the isolated local daemon.

Local verification

Base 6146aa1170f415fcc825ed9bddc4eacbeb937a12 · Candidate 5a2b745d431baaa112869c48fe3e846f1b3d749a · macOS-27.0.1-arm64-arm-64bit-Mach-O

Check Base Candidate
Copy a binary file from a running Docker container into a hashing sink path API cannot write to a binary sink 4 MiB streamed in bounded writes with matching SHA-256
Local Docker Engine Passed Passed
Existing path-based copy Passed Passed
Empty file copy Passed Passed
Copy before startup Passed Passed
Container file transfer tests — Passed

Replay receipt, commands, and logs

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.

Feature: Stream bytes out on copy_from_container

1 participant