Пример #1
0
        public static async Task <BA2FileEntryBuilder> Create(BA2FileEntryState state, Stream src, DiskSlabAllocator slab)
        {
            var builder = new BA2FileEntryBuilder
            {
                _state   = state,
                _rawSize = (int)src.Length,
                _dataSrc = src
            };

            if (!state.Compressed)
            {
                return(builder);
            }

            await using (var ms = new MemoryStream())
            {
                await using (var ds = new DeflaterOutputStream(ms))
                {
                    ds.IsStreamOwner = false;
                    await builder._dataSrc.CopyToAsync(ds);
                }

                builder._dataSrc = slab.Allocate(ms.Length);
                ms.Position      = 0;
                await ms.CopyToAsync(builder._dataSrc);

                builder._dataSrc.Position = 0;
                builder._size             = (int)ms.Length;
            }
            return(builder);
        }
Пример #2
0
        public static BA2FileEntryBuilder Create(BA2FileEntryState state, Stream src)
        {
            var builder = new BA2FileEntryBuilder {
                _state = state
            };

            using (var ms = new MemoryStream())
            {
                src.CopyTo(ms);
                builder._data = ms.ToArray();
            }
            builder._rawSize = builder._data.Length;

            if (state.Compressed)
            {
                using (var ms = new MemoryStream())
                {
                    using (var ds = new DeflaterOutputStream(ms))
                    {
                        ds.Write(builder._data, 0, builder._data.Length);
                    }
                    builder._data = ms.ToArray();
                }
                builder._size = builder._data.Length;
            }
            return(builder);
        }
Пример #3
0
        public BA2FileEntryBuilder(BA2FileEntryState state, Stream src)
        {
            _state = state;
            using (var ms = new MemoryStream())
            {
                src.CopyTo(ms);
                _data = ms.ToArray();
            }
            _rawSize = _data.Length;

            if (state.Compressed)
            {
                using (var ms = new MemoryStream())
                {
                    using (var ds = new DeflaterOutputStream(ms))
                    {
                        ds.Write(_data, 0, _data.Length);
                    }
                    _data = ms.ToArray();
                }

                _size = _data.Length;
            }
        }