Any additions for write-to-file short program

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Nov 18 23:09:28 UTC 2021


On Thu, Nov 18, 2021 at 10:20:48PM +0000, pascal111 via Digitalmars-d-learn wrote:
> In next program that rewrites original written texts into new files, I
> see that it may need some additions or we can accept it like this
> because it's just a simple program that achieve its task and doesn't
> need any philosophical additions.

I assume there's a reason you're reading the input file by line instead
of just copying it using larger fixed-size blocks?  Perhaps you have in
mind some kind of line-based filtering or processing eventually?

Because for copying a file, using a large, fixed-size block will work
much faster. Not to mention the code will be simpler. For example:

	auto inputFile = File(inputFilename, "r");
	auto outputFile = File(outputFilename, "w");

	enum bufferSize = 8194;
	inputFile.byChunk(bufferSize)	// read input in blocks of 8194 bytes
		.copy(outputFile.lockingBinaryWriter); // copy each block into output file


T

-- 
Javascript is what you use to allow third party programs you don't know
anything about and doing you know not what to run on your computer. --
Charles Hixson


More information about the Digitalmars-d-learn mailing list