Ejemplo n.º 1
0
        public void WriteDirectoryEntry(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }
            path = path.Replace(root_path, string.Empty).Replace(Path.DirectorySeparatorChar, '/');
            if (path.Length > 0 && path[0] == '/')
            {
                path = path.Substring(1);
            }
            DateTime lastWriteTime = Directory.Exists(path) ? Directory.GetLastWriteTime(path) : DateTime.Now;

            header.DirectoryName    = path;
            header.LastModification = lastWriteTime;
            header.CopyTo(ms);
        }
Ejemplo n.º 2
0
        public void Write(byte[] buffer)
        {
            long      pos    = offset;
            TarHeader header = new TarHeader();

            if (!string.IsNullOrWhiteSpace(path))
            {
                header.DirectoryName    = path;
                header.LastModification = dir.LastWriteTime;
                header.CopyTo(buffer, pos);
                pos += header.HeaderSize;
            }
            foreach (var file in dir.GetFiles())
            {
                header.FileName         = file.Name;
                header.LastModification = file.LastWriteTime;
                //  header.Write(file);
                header.CopyTo(buffer, pos);
                pos += header.HeaderSize;
                using (var stream = file.OpenRead())
                    stream.Read(buffer, (int)pos, (int)file.Length);
                pos += (int)file.Length;
            }
        }