File tree Expand file tree Collapse file tree 1 file changed +30
-13
lines changed Expand file tree Collapse file tree 1 file changed +30
-13
lines changed Original file line number Diff line number Diff line change 71
71
print ('Failed to run the query to generate output file.' )
72
72
exit (1 )
73
73
74
- # Remove the leading " and trailing " bytes from the file
75
- len = os .stat (outputFile ).st_size
76
- f = open (outputFile , "rb" )
77
- try :
78
- quote = f .read (6 )
79
- if quote != b"\x02 \x01 \x86 '\x85 '" :
80
- print ("Unexpected start characters in file." , quote )
81
- contents = f .read (len - 21 )
82
- quote = f .read (15 )
83
- if quote != b'\x0e \x01 \x08 #select\x01 \x01 \x00 s\x00 ' :
84
- print ("Unexpected end character in file." , quote )
85
- finally :
86
- f .close ()
74
+ # Remove the leading and trailing bytes from the file
75
+ length = os .stat (outputFile ).st_size
76
+ if length < 20 :
77
+ contents = b''
78
+ else :
79
+ f = open (outputFile , "rb" )
80
+ try :
81
+ countTillSlash = 0
82
+ foundSlash = False
83
+ slash = f .read (1 )
84
+ while slash != b'' :
85
+ if slash == b'/' :
86
+ foundSlash = True
87
+ break
88
+ countTillSlash += 1
89
+ slash = f .read (1 )
90
+
91
+ if not foundSlash :
92
+ countTillSlash = 0
93
+
94
+ f .seek (0 )
95
+ quote = f .read (countTillSlash )
96
+ print ("Start characters in file skipped." , quote )
97
+ post = b'\x0e \x01 \x08 #select\x01 \x01 \x00 s\x00 '
98
+ contents = f .read (length - len (post ) - countTillSlash )
99
+ quote = f .read (len (post ))
100
+ if quote != post :
101
+ print ("Unexpected end character in file." , quote )
102
+ finally :
103
+ f .close ()
87
104
88
105
f = open (outputFile , "wb" )
89
106
f .write (contents )
You can’t perform that action at this time.
0 commit comments