Ejemplo n.º 1
0
        public bool Load(byte[] data)
        {
            Blocks.Clear();

            int pos = 0;

            while (pos < data.Length)
            {
                var chunkdata = data.Skip(pos).Take(4).ToArray();
                var chunk     = Encoding.UTF8.GetString(chunkdata, 0, 4);
                pos += 4;

                var size = BitConverter.ToInt32(data, pos);
                pos += 4;

                var buffer = data.Skip(pos).Take(size).ToArray();
                pos += size;

                var binary = new ChunkBlock();
                binary.Chunk  = chunk;
                binary.Buffer = buffer;
                Blocks.Add(binary);
            }

            if (pos != data.Length)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void AddChunk(string chunk, byte[] buffer)
        {
            var block = new ChunkBlock();

            block.Chunk  = chunk;
            block.Buffer = buffer;
            Blocks.Add(block);
        }