Skip to main content
GameDev.net gamedev.net
🔒 Locked

.net BinaryReader skipping bytes

Started by edwinnie May 13, 2004 at 7:27 PM 3 replies 3.4k views
Original Post
edwinnie
edwinnie
hihi suppose u got a byte offset indicating data to be extracted from a binary file, how would u do it efficiently, without forcing to use ReadBytes() to purpose skip the number of bytes offset, as this would incurr a huge allocation process if the binary file is huge. thx! Edwin
SiCrane
SiCrane
Off the top of my head: use the Seek() method of the FileStream.
joanusdmentia
joanusdmentia
You can use the BaseStream property of the BinaryReader to access the stream it''s reading from. And as SiCrane said, call Seek() on that.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The nly verdict is vengeance; a vendett o
edwinnie
edwinnie
yupz thx alots!
done!
Zipster
Zipster
MSDN provides the following caution:
quote:
MSDN on the BaseStream Property
CAUTION Using the underlying stream while reading or while using the BinaryReader can cause data loss and corruption. For example, the same bytes might be read more than once, bytes might be skipped, or character reading might become unpredictable.


A BinaryReader is more useful for turning raw binary data into actual data types, such as integers, floats, etc. You really shouldn''t need it unless you do those things, and in such cases you might as well create the readers on-the-fly as you need them.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.