In memory stream with 8192 blocks to avoid LOH issues. Since .NET places objects larger that 85000 bytes into LOH, avoid it as much as possible by using list of smaller blocks.
Inheritance: Stream
Exemple #1
0
        /// <summary>
        /// Create reusable stream.
        /// Disposing the stream only has the effect of resetting it.
        /// </summary>
        /// <returns></returns>
        public static ChunkedMemoryStream Static()
        {
            var cms = new ChunkedMemoryStream(new byte[BlockSize]);

            cms.GetReader();
            cms.GetWriter();
            cms.UseBufferedReader(string.Empty);
            return(cms);
        }
Exemple #2
0
        public IDbCommand CreateQuery(Revenj.Utility.ChunkedMemoryStream cms)
        {
            var writer = cms.GetWriter();

            writer.Write(Statement);
            writer.Flush();
            cms.Position = 0;
            return(PostgresCommandFactory.NewCommand(cms, Statement, Query.Selects.Count == 1));
        }
Exemple #3
0
        public void CopyTo(ChunkedMemoryStream other)
        {
            other.CurrentPosition = CurrentPosition;
            var total     = TotalSize >> BlockShift;
            var remaining = TotalSize & BlockAnd;

            if (other.TotalSize < total)
            {
                for (int i = other.Blocks.Count; i < total; i++)
                {
                    other.Blocks.Add(new byte[BlockSize]);
                }
            }
            for (int i = 0; i < total; i++)
            {
                Buffer.BlockCopy(Blocks[i], 0, other.Blocks[i], 0, BlockSize);
            }
            Buffer.BlockCopy(Blocks[total], 0, other.Blocks[total], 0, remaining);
        }
Exemple #4
0
        /// <summary>
        /// Convert provided stream content to PDF.
        /// Specify extension of the file
        /// </summary>
        /// <param name="content">file content</param>
        /// <param name="ext">file extension</param>
        /// <param name="disposeStream">dispose provided stream after conversion</param>
        /// <returns>PDF converted stream</returns>
        public static Stream Convert(Stream content, string ext, bool disposeStream)
        {
            var from = TemporaryResources.CreateFile(ext);
            var to   = from + ".pdf";
            var fs   = new FileStream(from, FileMode.Create, FileAccess.Write);

            content.CopyTo(fs);
            fs.Close();
            if (disposeStream)
            {
                content.Dispose();
            }
            RunConverter(from);
            var cms = ChunkedMemoryStream.Create();

            using (var f = new FileStream(to, FileMode.Open, FileAccess.Read))
            {
                f.CopyTo(cms);
            }
            File.Delete(from);
            File.Delete(to);
            cms.Position = 0;
            return(cms);
        }
Exemple #5
0
 public CustomWriter(ChunkedMemoryStream cms)
     : base(cms)
 {
 }