Skip to content

Instantly share code, notes, and snippets.

@sdcb
Created March 7, 2019 01:35
Show Gist options
  • Save sdcb/66c507c6bd8f57c8e8333818c6ef48bb to your computer and use it in GitHub Desktop.
Save sdcb/66c507c6bd8f57c8e8333818c6ef48bb to your computer and use it in GitHub Desktop.
Effectively download SqlFileStream from ASP.NET Core
public class AspNetSqlFileStream : Stream
{
public SqlFileStream SqlStream { get; }
public IDbConnection Connection { get; }
public IDbTransaction Transaction { get; }
public AspNetSqlFileStream(SqlFileStream sqlStream, IDbConnection connection, IDbTransaction transaction)
{
SqlStream = sqlStream;
Connection = connection;
Transaction = transaction;
}
public override bool CanRead
{
get { return SqlStream.CanRead; }
}
public override bool CanSeek
{
get { return SqlStream.CanSeek; }
}
public override bool CanWrite
{
get { return SqlStream.CanWrite; }
}
public override void Flush()
{
SqlStream.Flush();
}
public override long Length
{
get { return SqlStream.Length; }
}
public override long Position
{
get
{
return SqlStream.Position;
}
set
{
SqlStream.Position = value;
}
}
public override int Read(byte[] buffer, int offset, int count)
{
return SqlStream.Read(buffer, offset, count);
}
public override long Seek(long offset, SeekOrigin origin)
{
return SqlStream.Seek(offset, origin);
}
public override void SetLength(long value)
{
SqlStream.SetLength(value);
}
public override void Write(byte[] buffer, int offset, int count)
{
SqlStream.Write(buffer, offset, count);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
SqlStream.Dispose();
Transaction.Dispose();
Connection.Dispose();
}
base.Dispose(disposing);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment