Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("USAGE: ArchiveMaker fileName.tar <fileToAdd.ext> [. more files..]");
                return;
            }
            using (FileStream archUsTar = File.Create(args[0]))
            {
                using (TarWriter legacyTar = new TarWriter(archUsTar))
                {
                    for (int i = 1; i < args.Length; ++i)
                    {
                        legacyTar.Write(args[i]);
                    }
                }
            }

            Console.WriteLine("Examine tar file: {0}", args[0]);
            using (FileStream 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 (FileStream unarchFile = File.OpenRead(args[0]))
            {
                TarReader reader = new TarReader(unarchFile);
                reader.ReadToEnd("out_dir\\data");
            }
        }
		public void ReadTarFile (string cleanUrl, Coherent.UI.ResourceResponse response)
		{
			string archivePath = Path.Combine(GetArchiveFolder(), m_ArchiveName);
			using (FileStream unarchFile = File.OpenRead(archivePath))
			{
				TarReader reader = new TarReader(unarchFile);
				while (reader.MoveNext(true))
				{
					var path = reader.FileInfo.FileName;
					
					if (path == cleanUrl)
					{
						using (MemoryStream ms = new MemoryStream((int)reader.FileInfo.SizeInBytes))
						{
							reader.Read(ms);
							byte[] buffer = ms.GetBuffer();
							RespondWithBytes(buffer, response);
						}
						
						break;
					}
				}
			}
		}