Skip to content

Instantly share code, notes, and snippets.

@gtechsltn
Forked from brentworden/DataReaderExtensions.cs
Created March 26, 2025 02:58
Show Gist options
  • Select an option

  • Save gtechsltn/fe436f6e637fd1c6de1675a97bf045ae to your computer and use it in GitHub Desktop.

Select an option

Save gtechsltn/fe436f6e637fd1c6de1675a97bf045ae to your computer and use it in GitHub Desktop.

Revisions

  1. @brentworden brentworden renamed this gist Aug 30, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @brentworden brentworden revised this gist Jun 15, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.cs
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ public static byte[] GetBytes(this IDataReader reader, int column) {
    long offset = 0L;
    long n = 0L;
    do {
    n = reader.GetBytes(5, offset, buff, 0, buff.Length);
    n = reader.GetBytes(column, offset, buff, 0, buff.Length);
    ms.Write(buff, 0, (int)n);
    offset += n;
    } while (n >= buff.Length);
  3. @invalid-email-address Anonymous created this gist Jun 9, 2012.
    27 changes: 27 additions & 0 deletions gistfile1.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    using System.Data;
    using System.IO;

    namespace Extensions.Data {

    public static class DataReaderExtensions {

    /*
    * Extension method on IDataReader that reads the entire contents of a large binary column using a single method call.
    * Sample usage:
    * byte[] bytes = reader.GetBytes(columnIndex);
    */
    public static byte[] GetBytes(this IDataReader reader, int column) {
    using (MemoryStream ms = new MemoryStream()) {
    byte[] buff = new byte[8192];
    long offset = 0L;
    long n = 0L;
    do {
    n = reader.GetBytes(5, offset, buff, 0, buff.Length);
    ms.Write(buff, 0, (int)n);
    offset += n;
    } while (n >= buff.Length);
    return ms.ToArray();
    }
    }
    }
    }