12
1
Your task today will be to take an existing file and append zeros to it until it reaches a certain size.
You must write a program or function which takes the name of a file in the current directory f
and a number of bytes b
. While maintaining the original content of f
, you must write zeroes (null bytes, not ascii 0s) to the end so that its new size is b
bytes.
You may assume that f
only has alphanumeric ascii in its name, that you have full permissions over it, that it initially is not larger than b
, but may be as large as b
, and that there is infinite free disk space.
You may not assume f
is nonempty, or that it does not already contain null bytes.
Other existing files should not be modified and new files should not exist after execution ends.
Test Cases
Contents of f | b | Resulting contents of f 12345 | 10 | 1234500000 0 | 3 | 000 [empty] | 2 | 00 [empty] | 0 | [empty] 123 | 3 | 123
@totallyhuman it initially is not larget than
b
– Adám – 2017-06-09T17:56:16.373Can we take the contents of the file as input and output the modified contents? – Shaggy – 2017-06-09T18:21:19.993
May we use libraries? – Adám – 2017-06-09T18:35:09.027
1@Phoenix The problem is that Dennis put the library in a far away folder (not my choice). Can I count as if it was available in the search path? – Adám – 2017-06-09T18:40:19.703
Can we assume the file will not already contain null bytes? – Dom Hastings – 2017-06-09T19:37:14.097