コード例 #1
0
 public ComStream(win32.IStream source)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     this.source = source;
     this.mInt64 = iop.Marshal.AllocCoTaskMem(8);
 }
コード例 #2
0
ファイル: ComIStream.cs プロジェクト: tekcor/vvvv-sdk
        public void CopyTo(win32.IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
        {
            if (!this.source.CanRead)
            {
                throw new NotSupportedException("Source stream doesn't support reading.");
            }
            using (var destination = new ComStream(pstm))
            {
                if (!destination.CanWrite)
                {
                    throw new NotSupportedException("Destination stream doesn't support writing.");
                }
                var buffer = MemoryPool <byte> .GetArray();

                try
                {
                    var totalBytesRead    = 0L;
                    var totalBytesWritten = 0L;
                    var chunkLength       = buffer.Length;
                    if (cb < chunkLength)
                    {
                        chunkLength = (int)cb;
                    }
                    while (totalBytesWritten < cb)
                    {
                        // Read
                        var bytesRead = this.source.Read(buffer, 0, chunkLength);
                        if (bytesRead == 0)
                        {
                            break;
                        }
                        totalBytesRead += bytesRead;
                        // Write
                        var previousPosition = destination.Position;
                        destination.Write(buffer, 0, bytesRead);
                        var bytesWritten = destination.Position - previousPosition;
                        if (bytesWritten == 0)
                        {
                            break;
                        }
                        totalBytesWritten += bytesWritten;

                        if (bytesRead != bytesWritten)
                        {
                            break;
                        }
                    }
                    iop.Marshal.WriteInt64(pcbRead, totalBytesRead);
                    iop.Marshal.WriteInt64(pcbWritten, totalBytesWritten);
                }
                finally
                {
                    MemoryPool <byte> .PutArray(buffer);
                }
            }
        }
コード例 #3
0
ファイル: ComStream.cs プロジェクト: tekcor/vvvv-sdk
 public ComStream(win32.IStream source)
 {
     this.source = source;
     this.mInt64 = iop.Marshal.AllocCoTaskMem(8);
 }
コード例 #4
0
ファイル: ComIStream.cs プロジェクト: tekcor/vvvv-sdk
 public void Clone(out win32.IStream ppstm)
 {
     ppstm = new ComIStream(this.source);
 }