/// <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); }
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)); }
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); }
/// <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); }
public CustomWriter(ChunkedMemoryStream cms) : base(cms) { }