예제 #1
0
        public void Load(string url, Action <int> AddBytes)
        {
            int from   = Files[0].offset;
            int to     = Files[Files.Count - 1].offset + Files[Files.Count - 1].CompressedSize;
            int length = to - from;

            using (var response = Download.GetResponse(url, from, to))
            {
                Stream stream;
                if (response != null && (stream = response.GetResponseStream()) != null)
                {
                    byte[] buf = new byte[BufferSize];
                    int    pos = from;

                    for (int i = 0; i < Files.Count; i++)
                    {
                        PackFile file = Files[i];
                        using (FileStream fs = file.Info.Create())
                            using (MemoryStream ms = new MemoryStream(BufferSize))
                                using (DeflateStream ds = new DeflateStream(ms, CompressionMode.Decompress))
                                {
                                    int left;
                                    while ((left = file.offset + file.CompressedSize - pos) > 0)
                                    {
                                        int read = stream.Read(buf, 0, left > BufferSize ? BufferSize : left);
                                        AddBytes(read);
                                        pos += read;

                                        ms.Position = 0;
                                        ms.SetLength(0);
                                        ms.Write(buf, 0, read);

                                        ms.Position = 0;
                                        ds.CopyTo(fs);
                                    }
                                }

                        if (i + 1 < Files.Count && Files[i + 1].offset > pos)
                        {
                            // read up to next file
                            int left;
                            while ((left = Files[i + 1].offset - pos) > 0)
                            {
                                int read = stream.Read(buf, 0, left > BufferSize ? BufferSize : left);
                                pos += read;
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        public static PackObject ReadNew(PacketStream stream, string path)
        {
            int    type   = stream.ReadByte();
            string name   = Path.Combine(path, stream.ReadStringShort());
            bool   isLast = (type & 2) > 0;

            if ((type & ~2) == (int)PackObjectType.File)
            {
                PackFile file = new PackFile(new FileInfo(name));
                file.ReadHeader(stream);
                file.IsLast = isLast;
                return(file);
            }
            else
            {
                PackDir dir = new PackDir(new DirectoryInfo(name));
                dir.IsLast = isLast;
                return(dir);
            }
        }
예제 #3
0
 static int SortOffsets(PackFile p1, PackFile p2)
 {
     return(p1.offset.CompareTo(p2.offset));
 }