Пример #1
0
        private static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("USAGE: ArchiveMaker fileName.tar <fileToAdd.ext> [. more files..]");
                return;
            }
            using (var archUsTar = File.Create(args[0]))
                using (var tar = new TarWriter(archUsTar))
                {
                    tar.WriteDirectoryEntry("test_dir");
                    for (int i = 1; i < args.Length; ++i)
                    {
                        tar.Write(args[i]);
                    }
                }

            Console.WriteLine("Examine tar file: {0}", args[0]);
            using (var examiner = File.OpenRead(args[0]))
            {
                TarReader tar = new TarReader(examiner);
                while (tar.MoveNext(true))
                {
                    Console.WriteLine("File: {0}, Owner: {1}", tar.FileInfo.FileName, tar.FileInfo.UserName);
                }
            }

            using (var unarchFile = File.OpenRead(args[0]))
            {
                TarReader reader = new TarReader(unarchFile);
                reader.ReadToEnd("out_dir\\data");
            }
        }
Пример #2
0
        /// <summary>
        /// Adds a directory to the currently opened archive.
        /// </summary>
        private void AddDirectory(string path, int userId = 0, int groupId = 0, int mode = 493 /* 0755 */, bool internalCall = false)
        {
            if (!internalCall)
            {
                EnsureDirectory(path, userId, groupId);
            }

            tarWriter.WriteDirectoryEntry(path, userId, groupId, mode);
            createdDirs.Add(path);
        }