Exemplo n.º 1
0
        public static Dictionary <string, TarFileInfo> ListFileInfos(Stream inputStream)
        {
            long position = 0;
            var  buffer   = new byte[512 * 512];
            var  output   = new Dictionary <string, TarFileInfo>();

            while (true)
            {
                var header = Utils.ReadStruct <Header>(inputStream);
                var magic  = ToString(header.Magic);
                position += 512;

                if (magic != "ustar ")
                {
                    break;
                }

                var filename = ToString(header.Prefix) + ToString(header.Name);
                var size     = Convert.ToInt64(ToString(header.Size), 8);

                switch (header.TypeFlag)
                {
                case '0':     // Regular file
                case '5':     // Directory
                    output[filename] = new TarFileInfo
                    {
                        Filename = filename,
                        Position = position,
                        Modified = _utcTime.AddSeconds((Convert.ToInt64(ToString(header.MTime), 8))),
                        Type     = (header.TypeFlag == '0') ? TarFiletype.File : TarFiletype.Directory,
                        Size     = size
                    };
                    break;
                }

                // Skip contents of file and align to 512 byte chunk boundary.
                var skipBytes = size + ((512 - ((position + size) % 512)) % 512);
                Skip(inputStream, skipBytes);
                position += skipBytes;

                Logger.Debug("Listing file from tar(" + size + "): \"" + filename + "\"");
            }

            inputStream.Close();

            return(output);
        }
Exemplo n.º 2
0
 public static Stream SkipToData(Stream stream, TarFileInfo fileInfo)
 {
     Skip(stream, fileInfo.Position);
     return stream;
 }
Exemplo n.º 3
0
 public static Stream SkipToData(Stream stream, TarFileInfo fileInfo)
 {
     Skip(stream, fileInfo.Position);
     return(stream);
 }
Exemplo n.º 4
0
        public static Dictionary<string, TarFileInfo> ListFileInfos(Stream inputStream)
        {
            long position = 0;
            var buffer = new byte[512 * 512];
            var output = new Dictionary<string, TarFileInfo>();

            while (true)
            {
                var header = Utils.ReadStruct<Header>(inputStream);
                var magic = ToString(header.Magic);
                position += 512;

                if (magic != "ustar ") break;

                var filename = ToString(header.Prefix) + ToString(header.Name);
                var size = Convert.ToInt64(ToString(header.Size), 8);

                switch (header.TypeFlag)
                {
                    case '0': // Regular file
                    case '5': // Directory
                        output[filename] = new TarFileInfo
                        {
                            Filename = filename,
                            Position = position,
                            Modified = _utcTime.AddSeconds((Convert.ToInt64(ToString(header.MTime), 8))),
                            Type = (header.TypeFlag == '0') ? TarFiletype.File : TarFiletype.Directory,
                            Size = size
                        };
                        break;
                }

                // Skip contents of file and align to 512 byte chunk boundary.
                var skipBytes = size + ((512 - ((position + size) % 512)) % 512);
                Skip(inputStream, skipBytes);
                position += skipBytes;

                Logger.Debug("Listing file from tar(" + size + "): \"" + filename + "\"");
            }

            inputStream.Close();

            return output;
        }