예제 #1
0
        internal override unsafe bool WriteDataBlock(IntPtr itemHandle, Int32 numBytesToWrite)
        {
            byte *dataBlock = (byte *)itemHandle;

            if (this.m_compressionScheme == CompressionScheme.None)
            {
                Int32 numBytesWritten = 0;
                Int32 remainingBytes  = numBytesToWrite;

                while (remainingBytes > 0)
                {
                    Int32 *pNumBytesWritten = &numBytesWritten;
                    bool   success          = DryadLinqNative.WriteFile(this.m_fhandle,
                                                                        dataBlock,
                                                                        (UInt32)remainingBytes,
                                                                        (IntPtr)pNumBytesWritten,
                                                                        null);
                    if (!success)
                    {
                        throw new DryadLinqException(DryadLinqErrorCode.WriteFileError,
                                                     String.Format(SR.WriteFileError,
                                                                   Marshal.GetLastWin32Error()));
                    }

                    dataBlock      += numBytesWritten;
                    remainingBytes -= numBytesWritten;
                }
            }
            else
            {
                if (this.m_compressStream == null)
                {
                    if (this.m_compressionScheme == CompressionScheme.Gzip)
                    {
                        this.m_compressStream = new GZipStream(this.m_fstream,
                                                               CompressionMode.Compress);
                    }
                    else
                    {
                        throw new DryadLinqException(DryadLinqErrorCode.UnknownCompressionScheme,
                                                     SR.UnknownCompressionScheme);
                    }
                }
                // YY: Made an extra copy here. Could do better.
                byte[] buffer = new byte[numBytesToWrite];
                fixed(byte *pBuffer = buffer)
                {
                    DryadLinqUtil.memcpy(dataBlock, pBuffer, numBytesToWrite);
                }

                this.m_compressStream.Write(buffer, 0, numBytesToWrite);
            }
            return(true);
        }
예제 #2
0
        internal override unsafe bool WriteDataBlock(IntPtr itemHandle, Int32 numBytesToWrite)
        {
            byte *dataBlock = (byte *)itemHandle;

            byte[] buffer = new byte[numBytesToWrite];
            fixed(byte *pBuffer = buffer)
            {
                DryadLinqUtil.memcpy(dataBlock, pBuffer, numBytesToWrite);
            }

            this.m_stream.Write(buffer, 0, numBytesToWrite);
            return(true);
        }
예제 #3
0
        internal override unsafe DataBlockInfo ReadDataBlock()
        {
            DataBlockInfo blockInfo;

            blockInfo.DataBlock  = (byte *)Marshal.AllocHGlobal(DefaultBuffSize);
            blockInfo.ItemHandle = (IntPtr)blockInfo.DataBlock;
            byte[] buffer = new byte[DefaultBuffSize];
            blockInfo.BlockSize = this.m_stream.Read(buffer, 0, DefaultBuffSize);
            fixed(byte *pBuffer = buffer)
            {
                DryadLinqUtil.memcpy(pBuffer, blockInfo.DataBlock, blockInfo.BlockSize);
            }

            return(blockInfo);
        }
예제 #4
0
        internal override unsafe DataBlockInfo ReadDataBlock()
        {
            DataBlockInfo blockInfo;

            blockInfo.DataBlock  = (byte *)Marshal.AllocHGlobal(DefaultBuffSize);
            blockInfo.ItemHandle = (IntPtr)blockInfo.DataBlock;
            if (this.m_compressionScheme == CompressionScheme.None)
            {
                Int32 *pBlockSize = &blockInfo.BlockSize;
                bool   success    = DryadLinqNative.ReadFile(this.m_fhandle,
                                                             blockInfo.DataBlock,
                                                             DefaultBuffSize,
                                                             (IntPtr)pBlockSize,
                                                             null);
                if (!success)
                {
                    throw new DryadLinqException(DryadLinqErrorCode.ReadFileError,
                                                 String.Format(SR.ReadFileError,
                                                               Marshal.GetLastWin32Error()));
                }
            }
            else
            {
                if (this.m_compressStream == null)
                {
                    if (this.m_compressionScheme == CompressionScheme.Gzip)
                    {
                        this.m_compressStream = new GZipStream(this.m_fstream,
                                                               CompressionMode.Decompress);
                    }
                    else
                    {
                        throw new DryadLinqException(DryadLinqErrorCode.UnknownCompressionScheme,
                                                     SR.UnknownCompressionScheme);
                    }
                }
                // YY: Made an extra copy here. Could do better.
                byte[] buffer = new byte[DefaultBuffSize];
                blockInfo.BlockSize = this.m_compressStream.Read(buffer, 0, DefaultBuffSize);
                fixed(byte *pBuffer = buffer)
                {
                    DryadLinqUtil.memcpy(pBuffer, blockInfo.DataBlock, blockInfo.BlockSize);
                }
            }
            return(blockInfo);
        }