I have a list of files, and I need to read them each in a specific order in bytes [] of a given size. This in itself is not a problem for a single file, a simple while ((got = fs.Read (piece, 0, pieceLength))> 0) does the job perfectly. The last fragment of the file may be less than desired, which is excellent.
Now there is a difficult bit: if I have several files, I need to have one continuous stream, which means that if the last fragment of the file is less than lengthLength, then I need to read (itemLength-got) of the next file, and then continue to the end last file.
So essentially, with X files in mind, I will always read snippets that are exactly lengthLength long, except for the very last part of the very last file, which may be smaller.
I'm just wondering if there is anything in .net (3.5 SP1) that does the trick. My current approach is to create a class that takes a list of files and then provides a function Read(byte[] buffer, long index, long length)similar to FileStream.Read (). It should be pretty simple, because I donβt need to change the calling code that reads the data, but before I invent the wheel, I just wanted to check that the wheel is not already built into BCL.
Thanks:)
source
share