@@ -9,7 +9,7 @@ namespace SatorImaging.TarArchiver
99 public class TarHeader
1010 {
1111 const int BLOCK_SIZE = 512 ;
12- static readonly DateTime EPOCH = new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
12+ static readonly DateTime EPOCH = new ( 1970 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
1313 static readonly Encoding ArchiveEncoding = Encoding . UTF8 ;
1414
1515 enum EEntryType : byte
@@ -30,14 +30,14 @@ enum EEntryType : byte
3030 }
3131
3232
33- internal string Name { get ; set ; }
33+ internal string Name { get ; set ; } = string . Empty ;
3434 internal long Size { get ; set ; }
3535 internal DateTime LastModifiedTime { get ; set ; }
3636
3737
3838 internal void Write ( Stream output )
3939 {
40- byte [ ] buffer = stackalloc byte [ BLOCK_SIZE ] ;
40+ var buffer = ( stackalloc byte [ BLOCK_SIZE ] ) ;
4141
4242 WriteOctalBytes ( 511 , buffer , 100 , 8 ) ; // file mode
4343 WriteOctalBytes ( 0 , buffer , 108 , 8 ) ; // owner ID
@@ -65,14 +65,14 @@ internal void Write(Stream output)
6565 Span < byte > bytes12 = stackalloc byte [ 12 ] ;
6666 BinaryPrimitives_WriteInt64BigEndian ( bytes12 . Slice ( 4 ) , Size ) ;
6767 bytes12 [ 0 ] |= 0x80 ;
68- bytes12 . CopyTo ( buffer . AsSpan ( 124 ) ) ;
68+ bytes12 . CopyTo ( buffer . Slice ( 124 ) ) ;
6969 }
7070 }
7171
7272 int crc = RecalculateChecksum ( buffer ) ;
7373 WriteOctalBytes ( crc , buffer , 148 , 8 ) ;
7474
75- output . Write ( buffer , 0 , buffer . Length ) ;
75+ output . Write ( buffer ) ;
7676
7777 if ( nameByteCount > 100 )
7878 {
@@ -103,7 +103,7 @@ static void BinaryPrimitives_WriteInt64BigEndian(Span<byte> destination, long va
103103 }
104104
105105
106- static void WriteOctalBytes ( long value , byte [ ] buffer , int offset , int length )
106+ static void WriteOctalBytes ( long value , Span < byte > buffer , int offset , int length )
107107 {
108108 var val = Convert . ToString ( value , 8 ) ;
109109 var shift = length - val . Length - 1 ;
@@ -125,7 +125,7 @@ static void WriteStringBytes(ReadOnlySpan<byte> name, Span<byte> buffer, int len
125125 buffer . Slice ( i , length - i ) . Clear ( ) ;
126126 }
127127
128- static void WriteStringBytes ( string name , byte [ ] buffer , int offset , int length )
128+ static void WriteStringBytes ( string name , Span < byte > buffer , int offset , int length )
129129 {
130130 int i ;
131131
@@ -168,10 +168,10 @@ void WriteLongFilenameHeader(Stream output)
168168 ( byte ) ' ' ,
169169 } ;
170170
171- static int RecalculateChecksum ( byte [ ] buf )
171+ static int RecalculateChecksum ( Span < byte > buf )
172172 {
173173 // Set default value for checksum. That is 8 spaces.
174- eightSpaces . CopyTo ( buf , 148 ) ;
174+ eightSpaces . CopyTo ( buf . Slice ( 148 ) ) ;
175175
176176 // Calculate checksum
177177 var headerChecksum = 0 ;
0 commit comments