Skip to content

Instantly share code, notes, and snippets.

@Sebbyastian
Last active August 29, 2015 14:05
Show Gist options
  • Save Sebbyastian/93d2e7606b8475aa5a84 to your computer and use it in GitHub Desktop.
Save Sebbyastian/93d2e7606b8475aa5a84 to your computer and use it in GitHub Desktop.
Am I a prick or what?
class FileStream
: System.IO.FileStream
{
protected long this[string key]
{
get {
this.Position = 0;
int c, p = 0;
for (; ; )
{
c = this.ReadByte();
if (c < 0)
{
this.Write(Encoding.ASCII.GetBytes(key), 0, key.Length);
this.WriteByte((byte)'\0');
break;
}
if (p == key.Length && c == '\0')
{
break;
}
if (p == key.Length || c != key[p])
{
p = 0;
this.Position -= c == '\0' ? 0 : p - 1;
continue;
}
p++;
}
return this.Position - p;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment