Anton
Anton

Reputation: 1

Limiting a stream size

I'm working on C# project and I want to read a single file from multiple threads using streams in the following manner:

  1. A file is logically divided into "chunks" of fixed size.
  2. Each thread gets it's own stream representing a "chunk".

The problem that I want use a Stream interface and I want to limit the size of each chunk so that the corresponding stream "ends" when it reaches the chunk size.

Is there something available in standard library or my only option is to write my own implementation of Stream?

Upvotes: 0

Views: 1410

Answers (1)

Haris
Haris

Reputation: 788

There is an overload in the Streamreader class for Streamreader.Read which allows you to limit the amount of characters read. An example can be found here: http://msdn.microsoft.com/en-us/library/9kstw824.aspx

The line you are looking for is sr.Read(c, 0, c.Length); You simply set up a char array and decide on the maximum amount of characters that are going to be read (the third argument).

Upvotes: 1

Related Questions