COPY_CHUNK
COPY_CHUNK = 1048576
Bytes read per iteration when a body arrives as a stream.
Turns a put body into the pieces one endpoint takes.
Every remote provider faces the same three problems and none of them is vendor-specific: a body arrives as a string or as a stream, a stream may not be able to say how long it is, and a body too large for one request has to be cut into uniform pieces with a short one at the end. The vendor decides what a piece is called and how large it may be; cutting it is arithmetic.
A short read is never silently accepted. A read that fails mid-stream raises naming the key, because a provider that returned what it had would write a truncated object that no reader can tell from a real one.
sliceStream(resource $stream, int $partSize, string $first, string $key) : \Generator<mixed,void>
Cuts a stream into uniform pieces.
| resource | $stream | An open readable stream, positioned after $first. |
| int | $partSize | Bytes per piece. |
| string | $first | The piece already read in order to decide that one request would not carry the body. |
| string | $key | Object key, for error messages. |
When the stream fails mid-read.
Every piece the same size except the last. A body ending exactly on a boundary yields no empty final piece.
readExactly(resource $stream, int $want, string $key) : string
Reads a fixed number of bytes, or fewer at the end of the stream.
| resource | $stream | An open readable stream. |
| int | $want | Bytes to read. |
| string | $key | Object key, for error messages. |
When a read fails.
Exactly $want bytes, or fewer when the stream ended.