public override Stream GetStream(bool decompress = true)
        {
            var stream = mStream;

            if (IsCompressed && decompress)
            {
                if (mDecompressedStream == null)
                {
                    var compression = new LBCompression();
                    mDecompressedStream = compression.Decompress(mStream);
                }

                stream = mDecompressedStream;
            }

            return(new StreamView(stream, 0, stream.Length));
        }
        public override Stream GetStream(bool decompress = true)
        {
            if (decompress && IsCompressed)
            {
                if (mDecompressedStream == null)
                {
                    var compression = new LBCompression();
                    mDecompressedStream = compression.Decompress(new StreamView(mBaseStream, Offset, Length), DecompressedLength);
                }

                return(mDecompressedStream);
            }
            else
            {
                return(new StreamView(mBaseStream, Offset, Length));
            }
        }
示例#3
0
        public void AddFile(int handle, short userId, Stream stream, bool ownsStream, ConflictPolicy policy)
        {
            bool replacing = false;

            if (mEntryMap.TryGetValue(handle, out var foundEntry))
            {
                switch (policy.Kind)
                {
                case ConflictPolicy.PolicyKind.ThrowError:
                    throw new FileExistsException <int>(handle);

                case ConflictPolicy.PolicyKind.Replace:
                    // Handled later
                    replacing = true;
                    break;

                case ConflictPolicy.PolicyKind.Ignore:
                    return;

                default:
                    throw new ArgumentOutOfRangeException(nameof(policy));
                }
            }


            bool compressed = false;

            Entry entry;
            var   entryStream = stream;

            if (compressed)
            {
                var compression = new LBCompression();
                entryStream = compression.Compress(stream);
                ownsStream  = true;
            }

            if (!replacing)
            {
                var fileStream = stream as FileStream ??
                                 throw new NotSupportedException("Can't add files without filename information to this file system");

                var extension = Path.GetExtension(fileStream.Name);
                if (extension == null)
                {
                    throw new NotSupportedException("Can't add files without file extension information to this file system");
                }


                entry = new MemoryEntry(handle, entryStream, ownsStream, 1, compressed, ( int )stream.Length, userId, extension
                                        .ToUpper()
                                        .TrimStart('.'));
            }
            else
            {
                entry = new MemoryEntry(foundEntry.Handle, entryStream, ownsStream, foundEntry.Type, compressed, ( int )stream.Length, foundEntry.UserId,
                                        foundEntry.Extension);
            }

            mEntryMap[entry.Handle] = entry;
        }