2
2
3
3
using File = TagLib . File ;
4
4
5
- public class StripImageData
5
+ namespace StripImageData ;
6
+
7
+ public class Program
6
8
{
7
- private static byte [ ] image_data = new byte [ ] {
9
+ static readonly byte [ ] image_data = [
8
10
0xFF , 0xDA , 0x00 , 0x0C , 0x03 , 0x01 , 0x00 ,
9
11
0x02 , 0x11 , 0x03 , 0x11 , 0x00 , 0x3F , 0x00 ,
10
12
0x8C , 0x80 , 0x07 , 0xFF , 0xD9
11
- } ;
13
+ ] ;
12
14
13
15
public static void Main ( string [ ] args )
14
16
{
@@ -17,9 +19,9 @@ public static void Main (string [] args)
17
19
return ;
18
20
}
19
21
20
- ImageFile file = new ImageFile ( args [ 0 ] ) ;
21
-
22
- file . Mode = File . AccessMode . Write ;
22
+ var file = new ImageFile ( args [ 0 ] ) {
23
+ Mode = File . AccessMode . Write
24
+ } ;
23
25
24
26
long greatest_segment_position = 0 ;
25
27
long greatest_segment_length = 0 ;
@@ -48,25 +50,25 @@ public static void Main (string [] args)
48
50
return ;
49
51
}
50
52
51
- System . Console . WriteLine ( "Stripping data segment at {0}" , greatest_segment_position ) ;
53
+ Console . WriteLine ( $ "Stripping data segment at { greatest_segment_position } " ) ;
52
54
53
55
file . RemoveBlock ( greatest_segment_position , greatest_segment_length ) ;
54
56
file . Seek ( greatest_segment_position ) ;
55
57
file . WriteBlock ( image_data ) ;
56
58
file . Mode = File . AccessMode . Closed ;
57
59
}
58
60
59
- private static long SkipDataSegment ( ImageFile file )
61
+ static long SkipDataSegment ( ImageFile file )
60
62
{
61
63
long position = file . Tell ;
62
64
63
65
// skip sos maker
64
66
if ( file . ReadBlock ( 2 ) . ToUInt ( ) != 0xFFDA )
65
- throw new Exception ( String . Format ( "Not a data segment at position: {0}" , position ) ) ;
67
+ throw new Exception ( $ "Not a data segment at position: { position } " ) ;
66
68
67
69
while ( true ) {
68
- if ( 0xFF == ( byte ) file . ReadBlock ( 1 ) [ 0 ] ) {
69
- byte maker = ( byte ) file . ReadBlock ( 1 ) [ 0 ] ;
70
+ if ( 0xFF == file . ReadBlock ( 1 ) [ 0 ] ) {
71
+ byte maker = file . ReadBlock ( 1 ) [ 0 ] ;
70
72
71
73
if ( maker != 0x00 && ( maker <= 0xD0 || maker >= 0xD7 ) )
72
74
break ;
@@ -75,42 +77,41 @@ private static long SkipDataSegment (ImageFile file)
75
77
76
78
long length = file . Tell - position - 2 ;
77
79
78
- System . Console . WriteLine ( "Data segment of length {0 } found at {1}" , length , position ) ;
80
+ Console . WriteLine ( $ "Data segment of length { length } found at { position } " ) ;
79
81
80
82
return length ;
81
83
}
82
84
83
- private class ImageFile : File {
85
+ class ImageFile : File {
84
86
85
87
// Hacky implementation to make use of some methods defined in TagLib.File
86
88
87
- public ImageFile ( string path )
88
- : base ( new File . LocalFileAbstraction ( path ) ) { }
89
+ public ImageFile ( string path ) : base ( new LocalFileAbstraction ( path ) ) { }
89
90
90
- public override Tag GetTag ( TagLib . TagTypes type , bool create )
91
+ public override Tag GetTag ( TagTypes type , bool create )
91
92
{
92
- throw new System . NotImplementedException ( ) ;
93
+ throw new NotImplementedException ( ) ;
93
94
}
94
95
95
96
public override Properties Properties {
96
97
get {
97
- throw new System . NotImplementedException ( ) ;
98
+ throw new NotImplementedException ( ) ;
98
99
}
99
100
}
100
101
101
- public override void RemoveTags ( TagLib . TagTypes types )
102
+ public override void RemoveTags ( TagTypes types )
102
103
{
103
- throw new System . NotImplementedException ( ) ;
104
+ throw new NotImplementedException ( ) ;
104
105
}
105
106
106
107
public override void Save ( )
107
108
{
108
- throw new System . NotImplementedException ( ) ;
109
+ throw new NotImplementedException ( ) ;
109
110
}
110
111
111
112
public override Tag Tag {
112
113
get {
113
- throw new System . NotImplementedException ( ) ;
114
+ throw new NotImplementedException ( ) ;
114
115
}
115
116
}
116
117
}
0 commit comments