private void copy_io_stream_async(CopyStreamItem item)
        {
            if (buffer_sync == null)
            {
                buffers_async = new StreamAsyncWriter();
                buffers_async.WriteChunkCallback = new WriteChunk(write_chunk_finish_async);
                buffers_async.PrepareBuffers(buffers_count, buffer_size);
            }

            int  bytes_readed  = 0;
            bool continue_copy = true;

            while (continue_copy)
            {
                StreamWriterBuffer buf = buffers_async.WaitForFreeBuffer();
                bytes_readed          = item.SourceStream.Read(buf.buffer, 0, buffer_size);
                buf.ActualBytes       = bytes_readed;
                buf.DestinationStream = item.DestinationStream;
                buf.DestinationName   = item.DestinationName;
                buffers_async.Enqueue(buf);

                //notify chunk read finish

                continue_copy = bytes_readed != 0;
            }
        }
        private void copy_one_item(string source, string destination)
        {
            FileStream src_stream  = null;
            FileStream dest_stream = null;

            //try open source
            try
            {
                src_stream = internal_create_source_stream(source);
            }
            catch (Exception ex)
            {
                if (src_stream != null)
                {
                    src_stream.Close();
                }
                AbortJob = !process_error
                               (string.Format("Cannot open source file '{0}'", source),
                               ex);
                return;
            }

            //try open destination
            try
            {
                dest_stream = internal_create_destination_stream(destination, src_stream.Length);
            }
            catch (Exception ex)
            {
                src_stream.Close();
                if (dest_stream != null)
                {
                    dest_stream.Close();
                }
                AbortJob = !process_error
                               (string.Format("Cannot open destination file\n'{0}'.", destination),
                               ex);
                return;
            }

            CopyStreamItem copy_item = new CopyStreamItem();

            copy_item.BytesTransferred  = 0;
            copy_item.DestinationName   = destination;
            copy_item.DestinationStream = dest_stream;
            copy_item.SourceName        = source;
            copy_item.SourceStream      = src_stream;

            //which method use?
            if (internal_is_same_volume(src_stream.Handle, dest_stream.Handle))
            {
                //same volume - sync copy
                copy_io_stream_sync(copy_item);
            }
            else
            {
                //cross volumes - use async writer
                copy_io_stream_async(copy_item);
            }
        }
        private void copy_io_stream_sync(CopyStreamItem item)
        {
            if (buffer_sync.Length == 0)
            {
                buffer_sync = new byte[buffer_size];
            }

            int  bytes_readed  = 0;
            bool continue_copy = true;

            while (continue_copy)
            {
                bytes_readed = item.SourceStream.Read(buffer_sync, 0, buffer_size);

                //notifu chunk read

                item.DestinationStream.Write(buffer_sync, 0, bytes_readed);
                continue_copy          = bytes_readed != 0;
                item.BytesTransferred += bytes_readed;

                //time to notify chunk write
            }
        }
 public CopyChunkTransferredEventArgs(CopyStreamItem item)
 {
     CopyItem = item;
 }