mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 14:10:30 +03:00
added File.byChunk
This commit is contained in:
parent
02243ab1f3
commit
196cfd9cac
1 changed files with 27 additions and 0 deletions
27
std/stdio.d
27
std/stdio.d
|
@ -754,6 +754,33 @@ to this file. */
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Iterates through a file a chunk at a time by using $(D foreach).
|
||||
|
||||
Example:
|
||||
|
||||
---------
|
||||
void main()
|
||||
{
|
||||
foreach (ubyte[] buffer; stdin.byChunk(4096))
|
||||
{
|
||||
... use buffer ...
|
||||
}
|
||||
}
|
||||
---------
|
||||
|
||||
The content of $(D buffer) is reused across calls. In the example
|
||||
above, $(D buffer.length) is 4096 for all iterations, except for the
|
||||
last one, in which case $(D buffer.length) may be less than 4096 (but
|
||||
always greater than zero).
|
||||
|
||||
In case of an I/O error, an $(D StdioException) is thrown.
|
||||
*/
|
||||
chunks byChunk(size_t chunkSize)
|
||||
{
|
||||
return chunks(this, chunkSize);
|
||||
}
|
||||
|
||||
/**
|
||||
$(D Range) that locks the file and allows fast writing to it.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue