3

I am playing around with the idea of using Dokan, the user-mode file system helper library, to create a file system around the new OneDrive API that has recently come out. I realise that there are existing tools to do this but I want to try and make an optimised version around read-only media streaming from the service for use with Plex.

I want to try and optimise the experience by having some kind of buffer, somewhere between 20-50 megabytes, that is used to make the whole experience smoother if the internet connection being used to access OneDrive API is variable and I also want to download chunks of data from OneDrive in parallel to maximise the bandwidth of the connection.

All this means that when Dokan is requesting bytes from the file residing on OneDrive that it will be essentially reading from this buffer whilst I simultaneously write into it, potentially with gaps in the data from the parallel segments not having completing in order and I am unsure what is the most efficient way of doing this!

I figured the most simple way would be to allocate a large byte array, start to fill it up and then as data is read from it by Dokan, do a Buffer.BlockCopy to a new array, essentially discarding the read data and leaving room at the end to then allow more data to be downloaded and filled in. This process would then try and maintain the buffer at its maximum size as the whole file is streamed through, appearing to the consumer that it is a local file.

Would continuously BlockCopying a large byte array like this be a terrible way to do it and is there an established pattern for achieving something like this more easily in .NET? I have been researching for a few hours now but can't find any examples that are trying to do the same thing I am even though I would have thought it would be quite common!

Any suggestions or examples you can think of would be very gratefully received, thank you!

Jim
  • 31
  • 1
  • I think it's better to use `MemoryStream`, and just write data to the stream rather than copying byte arrays. – shlatchz Apr 13 '16 at 18:14

0 Answers0