Skip to content

Instantly share code, notes, and snippets.

@FrankDeGroot
Created September 24, 2013 12:15
Show Gist options
  • Save FrankDeGroot/6683882 to your computer and use it in GitHub Desktop.
Save FrankDeGroot/6683882 to your computer and use it in GitHub Desktop.
Open IDataReader result column as stream using IDataReader.GetBytes.
using System;
using System.Data;
using System.IO;
namespace Company.Product
{
internal class DataReaderStream : Stream
{
private long _position = 0L;
private readonly IDataReader _reader;
private readonly int _index;
public DataReaderStream(IDataReader reader, int index)
{
_reader = reader;
_index = index;
}
public override int Read(byte[] buffer, int offset, int count)
{
long read = _reader.GetBytes(_index, _position, buffer, offset, count);
_position += read;
return (int)read;
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}
public override long Position
{
get { return _position; }
set { throw new NotSupportedException(); }
}
public override long Length
{
get { throw new NotSupportedException(); }
}
public override bool CanWrite
{
get { return false; }
}
public override bool CanRead
{
get { return true; }
}
public override bool CanSeek
{
get { return false; }
}
public override void SetLength(long value)
{
throw new NotSupportedException();
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
}
public override void Flush()
{
throw new NotSupportedException();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment