示例#1
0
        public Stream GetContent(PackageEntry entry)
        {
            Stream parentStream;
            var    offset = dataStart + entry.Offset + SegmentStream.GetOverallNestedOffset(s, out parentStream);
            var    path   = ((FileStream)parentStream).Name;

            return(new SegmentStream(File.OpenRead(path), offset, entry.Length));
        }
示例#2
0
        public Stream GetContent(uint hash)
        {
            PackageEntry e;

            if (!index.TryGetValue(hash, out e))
            {
                return(null);
            }

            Stream parentStream;
            var    offset = dataStart + e.Offset + SegmentStream.GetOverallNestedOffset(s, out parentStream);
            var    path   = ((FileStream)parentStream).Name;

            return(new SegmentStream(File.OpenRead(path), offset, e.Length));
        }
示例#3
0
            public Stream GetContent(PackageEntry entry)
            {
                Stream parentStream;
                var    baseOffset   = dataStart + entry.Offset;
                var    nestedOffset = baseOffset + SegmentStream.GetOverallNestedOffset(s, out parentStream);

                // Special case FileStream - instead of creating an in-memory copy,
                // just reference the portion of the on-disk file that we need to save memory.
                // We use GetType instead of 'is' here since we can't handle any derived classes of FileStream.
                if (parentStream.GetType() == typeof(FileStream))
                {
                    var path = ((FileStream)parentStream).Name;
                    return(new SegmentStream(File.OpenRead(path), nestedOffset, entry.Length));
                }

                // For all other streams, create a copy in memory.
                // This uses more memory but is the only way in general to ensure the returned streams won't clash.
                s.Seek(baseOffset, SeekOrigin.Begin);
                return(new MemoryStream(s.ReadBytes((int)entry.Length)));
            }