开发者

Writing a base64 string to a file without carriage returns

Will I run into problems if I write a base64 string into a file without breaking it up using carriage returns?

Is there a length where I'll run into difficulties writing and reading a big string in one go?

Right now the size of the strings I'm storing are about 100 characters but they ca开发者_如何学Cn get into the 10,000+ range - will that be a problem?

Thanks in advance.


You can have files as big as your file system allows with no line breaks in them.

Reading them, on the other hand, will be difficult for large files. I recommend a StreamReader or at least a buffer in the form of a byte array instead of trying to load it as a string.


That entirely depends on the app that reads the file. I certainly wouldn't do this if it is a native C/C++ app that reads it. A .NET or Java app shouldn't have any trouble with it, short from consuming more memory. MIME (RFC 2045) requires no more than 76 characters on a line and "=" for padding. I'd suggest you use that.


If the application that decodes the data is reading the file line at a time, it may not be the best use of resources. But the only way I can see it causing a problem is if the decoding application reads line at a time, the lines are really long and the decoding application is running low on memory.


To answer your direct question, yes there is a size that you will start to notice read/write performance issues if you are using a single large string; however, it depends on many things, including Disk IO, CPU load, and even free memory. On a semi-modern machine, I'd say you wont really have issues as long as your files are under 2-3 MB.

That said, Neil's advice to use a buffer is good advice, since it will yeild much better performance and allow you to display a progressbar, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜