Copy File Bytes with Partial Writes
Problem statement
Simulate the core data loop of a file-copy command. source contains the source file's bytes as integers from 0 through 255.
Read at most readChunkSize bytes at a time. A single write accepts at most maxWriteSize bytes, so keep writing until the entire current read buffer is stored. Return the destination bytes after the copy completes.
Function
copyFileBytes(source: int[], readChunkSize: int, maxWriteSize: int) → int[]Examples
Example 1
source = [0,255,1,2,3]readChunkSize = 3maxWriteSize = 2return = [0,255,1,2,3]The first three-byte read requires two writes, but no byte is lost.
Example 2
source = []readChunkSize = 4maxWriteSize = 1return = []An empty source creates an empty destination.
Constraints
0 <= source.length <= 100000.1 <= readChunkSize, maxWriteSize <= 100000.- Every source value is between 0 and 255.