예제 #1
0
 public static string ReadAsUtf8String(this TarFile file)
 {
     using (var r = new StreamReader(file.Open()))
     {
         return(r.ReadToEnd());
     }
 }
예제 #2
0
        public static string ReadAsUtf8String(this TarFile file)
        {
            // Use Encoding.UTF8 on a byte array instead of a StreamReader to make sure
            // we stop reading when we encounter a null (\0) character.
            using (var stream = file.Open())
            {
                byte[] data = new byte[stream.Length];
                stream.Read(data, 0, data.Length);

                return(Encoding.UTF8.GetString(data));
            }
        }
예제 #3
0
        /// <summary>
        /// Generates a <see cref="CpioFile"/> based on a list of <see cref="ArchiveEntry"/>
        /// values.
        /// </summary>
        /// <param name="archiveEntries">
        /// The values based on which to generate the <see cref="CpioFile"/>.
        /// </param>
        /// <param name="targetStream">
        /// The <see cref="Stream"/> which will hold the <see cref="CpioFile"/>.
        /// </param>
        public static void FromArchiveEntries(List <ArchiveEntry> archiveEntries, Stream targetStream)
        {
            using (TarFile cpioFile = new TarFile(targetStream, leaveOpen: true))
            {
                foreach (var entry in archiveEntries)
                {
                    WriteEntry(targetStream, entry);
                }

                WriteTrailer(targetStream);
            }
        }