Random access Raw file reader?

I can’t find a node that allows reading N number of raw bytes from some file at position P; just good old random access file IO. Am I missing it? Seems like a basic thing. Thanks!

i’m afraid there is indeed no such thing in core or addonpack and i am also now aware of such a contribution.

when creating your own plugin i’d suggest starting with the Template (Raw) and throwing in a FileStream

Thanks @joreg - yeah it’s pretty simple, which is why I was surprised to not find one. Stand by…

aren’t Reader (String Advcanced) or SequentialReader (File) nodes that go into that direction? I Think they are both older than the raw datatype…

the thing is that file access methods are designed for sequential reading of files, hence the name FileStream, but there is a trick with BaseStream.Seek and ReadBytes to improve performance a lot when doing random access: http://www.dotnetperls.com/seek

I’ve already got it working, using BinaryReader. My main performance concern is if the file is constantly being re-opened and closed every call to Evaluate(). The examples I found did no explicit close, so I assume it is being done when the handle goes out of scope. Or is there some better smarts at work?

Would putting the handle into a class variable and only doing the open when the input filename changed be worth it? For my use (reading large pointclouds out of a VERY large recorded file at 60fps) the overhead seems negligible and not worth the added complexity.

I’ll post my first stab at it and hopefully all you fine folks will have suggestions for improvement.

keep a spread of binaryreaders, just open them once and keep them open while needed

edit:
something like this

public void Evaluate(int spreadMax)
		{
			FBinaryReader.ResizeAndDispose(spreadMax, (i) => new BinaryReader(FFilename[i](i)));
						
			if (FFilename.IsChanged)
			{
				for (int i = 0; i < spreadMax; i++)
				{
					if (FFilename[i](i) != FBinaryReader[i](i).Filename)
					{
						FBinaryReader[i](i).Dispose();
						FBinaryReader[i](i) = new BinaryReader(FFilename[i](i));
					}
				}
			}

			for (int i = 0; i < spreadMax; i++)
			{
			  //io stuff here
			}
		}