/// <summary>
        /// Writes the media object to a stream.
        /// </summary>
        /// <param name="mediaId">The media id.</param>
        /// <param name="output">The output.</param>
        private void WriteMedia(int mediaId, Stream output)
        {
            using (NpgsqlConnection conn = FileHandlerHelpers.GetPgConnection())
            {
                int noid = 0;
                using (NpgsqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT data FROM \"MediaContent\" WHERE id=:id;";
                    cmd.Parameters.Add("id", mediaId);
                    noid = Convert.ToInt32(cmd.ExecuteScalar());
                }

                NpgsqlTransaction  tran        = conn.BeginTransaction();
                LargeObjectManager lbm         = new LargeObjectManager(conn);
                LargeObject        largeObject = lbm.Open(noid, LargeObjectManager.READWRITE);
                largeObject.Seek(0);
                int    size   = largeObject.Size();
                byte[] buffer = new byte[size];
                int    read   = 0;
                int    offset = 0;
                while (offset < size)
                {
                    read = largeObject.Read(buffer, offset, Math.Min(102400, size - offset));
                    output.Write(buffer, offset, read);
                    offset += 102400;
                }
                largeObject.Close();
                tran.Commit();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the contents of a LargeObject into a buffer.
        /// </summary>
        /// <param name="largeObject">The large object.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev02, 2008-08-08</remarks>
        private byte[] LargeObjectToBuffer(LargeObject largeObject)
        {
            largeObject.Seek(0);
            int size = largeObject.Size();

            byte[] buffer = new byte[size];

            int offset = 0;

            while (offset < size)
            {
                largeObject.Read(buffer, offset, Math.Min(chunkSize, size - offset));
                offset += chunkSize;
            }

            return(buffer);
        }
Ejemplo n.º 3
0
 public override int Read(byte [] buffer, int offset, int count)
 {
     return(obj.Read(buffer, offset, count));
 }