Пример #1
0
        private byte[] readblockdata(AllocationBlock ab)
        {
            byte[] data   = new byte[ab.datalength];
            long   offset = 0;
            int    len    = ab.datalength;
            int    dbsize = _BlockSize - _blockheader.Length - ab.keylen;

            ab.Blocks.ForEach(x =>
            {
                byte[] b = _datastore.ReadBlock(x);
                int c    = len;
                if (c > dbsize)
                {
                    c = dbsize;
                }
                Buffer.BlockCopy(b, _blockheader.Length + ab.keylen, data, (int)offset, c);
                offset += c;
                len    -= c;
            });
            if (ab.isCompressed)
            {
                data = MiniLZO.Decompress(data);
            }
            return(data);
        }
Пример #2
0
        internal byte[] GetData(int blocknumber, List <int> usedblocks)
        {
            lock (_lock)
            {
                AllocationBlock ab = FillAllocationBlock(blocknumber);
                usedblocks = ab.Blocks;
                byte[] data   = new byte[ab.datalength];
                long   offset = 0;
                int    len    = ab.datalength;
                int    dbsize = _BlockSize - _blockheader.Length - ab.keylen;
                ab.Blocks.ForEach(x =>
                {
                    byte[] b = _datastore.ReadBlock(x);
                    int c    = len;
                    if (c > dbsize)
                    {
                        c = dbsize;
                    }
                    Buffer.BlockCopy(b, _blockheader.Length + ab.keylen, data, (int)offset, c);
                    offset += c;
                    len    -= c;
                });
                if (ab.isCompressed)
                {
                    data = MiniLZO.Decompress(data);
                }

                return(data);
            }
        }
Пример #3
0
        private MGRB LoadBitmap(long offset)
        {
            MGRB bc = new MGRB();

            if (offset == -1)
            {
                return(bc);
            }
            FileStream bmp = _bitmapFileRead;

            bmp.Seek(offset, SeekOrigin.Begin);
            var hdr = new byte[_hdrlen];

            bmp.Read(hdr, 0, hdr.Length);
            if (hdr[0] == (byte)'b' && hdr[1] == (byte)'m')
            {
                int c = Helper.ToInt32(hdr, 3);
                var b = new byte[c];
                bmp.Read(b, 0, c);
                if (hdr[2] == 1)
                {
                    b = MiniLZO.Decompress(b);
                }
                bc.Deserialize(fastBinaryJSON.BJSON.ToObject <MGRBData>(b));
            }
            else
            {
                log.Error("bitmap not recognized");
            }

            return(bc);
        }
Пример #4
0
        internal byte[] ReadBytes(long recnum, out StorageItem <T> meta)
        {
            meta = null;
            if (recnum >= _lastRecordNum)
            {
                return(null);
            }
            lock (_readlock)
            {
                long       off  = ComputeOffset(recnum);
                FileStream fs   = GetReadFileStreamWithSeek(off);
                byte[]     data = internalReadBytes(fs, out meta);

                if (meta.isCompressed > 0)
                {
                    data = MiniLZO.Decompress(data);
                }

                return(data);
            }
        }
Пример #5
0
        public object GetObjectHF(string key)
        {
            lock (_lock)
            {
                int alloc;
                if (_keys.Get(key, out alloc))
                {
                    AllocationBlock ab = FillAllocationBlock(alloc);
                    if (ab.deleteKey == false)
                    {
                        byte[] data   = new byte[ab.datalength];
                        long   offset = 0;
                        int    len    = ab.datalength;
                        int    dbsize = _BlockSize - _blockheader.Length - ab.keylen;
                        ab.Blocks.ForEach(x =>
                        {
                            byte[] b = _datastore.ReadBlock(x);
                            int c    = len;
                            if (c > dbsize)
                            {
                                c = dbsize;
                            }
                            Buffer.BlockCopy(b, _blockheader.Length + ab.keylen, data, (int)offset, c);
                            offset += c;
                            len    -= c;
                        });
                        if (ab.isCompressed)
                        {
                            data = MiniLZO.Decompress(data);
                        }

                        return(fastBinaryJSON.BJSON.ToObject(data));
                    }
                }
            }

            return(null);
        }