-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoverage.html
More file actions
1820 lines (1622 loc) · 65.8 KB
/
coverage.html
File metadata and controls
1820 lines (1622 loc) · 65.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>humanize: Go Coverage Report</title>
<style>
body {
background: black;
color: rgb(80, 80, 80);
}
body, pre, #legend span {
font-family: Menlo, monospace;
font-weight: bold;
}
#topbar {
background: black;
position: fixed;
top: 0; left: 0; right: 0;
height: 42px;
border-bottom: 1px solid rgb(80, 80, 80);
}
#content {
margin-top: 50px;
}
#nav, #legend {
float: left;
margin-left: 10px;
}
#legend {
margin-top: 12px;
}
#nav {
margin-top: 10px;
}
#legend span {
margin: 0 5px;
}
.cov0 { color: rgb(192, 0, 0) }
.cov1 { color: rgb(128, 128, 128) }
.cov2 { color: rgb(116, 140, 131) }
.cov3 { color: rgb(104, 152, 134) }
.cov4 { color: rgb(92, 164, 137) }
.cov5 { color: rgb(80, 176, 140) }
.cov6 { color: rgb(68, 188, 143) }
.cov7 { color: rgb(56, 200, 146) }
.cov8 { color: rgb(44, 212, 149) }
.cov9 { color: rgb(32, 224, 152) }
.cov10 { color: rgb(20, 236, 155) }
</style>
</head>
<body>
<div id="topbar">
<div id="nav">
<select id="files">
<option value="file0">github.com/bengarrett/sauce/humanize/bytes.go (100.0%)</option>
<option value="file1">github.com/bengarrett/sauce/humanize/dates.go (100.0%)</option>
<option value="file2">github.com/bengarrett/sauce/internal/layout/ansiflags.go (94.7%)</option>
<option value="file3">github.com/bengarrett/sauce/internal/layout/archive.go (100.0%)</option>
<option value="file4">github.com/bengarrett/sauce/internal/layout/audio.go (83.3%)</option>
<option value="file5">github.com/bengarrett/sauce/internal/layout/binarytext.go (100.0%)</option>
<option value="file6">github.com/bengarrett/sauce/internal/layout/bitmap.go (100.0%)</option>
<option value="file7">github.com/bengarrett/sauce/internal/layout/character.go (92.9%)</option>
<option value="file8">github.com/bengarrett/sauce/internal/layout/comnt.go (90.9%)</option>
<option value="file9">github.com/bengarrett/sauce/internal/layout/datatype.go (100.0%)</option>
<option value="file10">github.com/bengarrett/sauce/internal/layout/date.go (88.2%)</option>
<option value="file11">github.com/bengarrett/sauce/internal/layout/executable.go (100.0%)</option>
<option value="file12">github.com/bengarrett/sauce/internal/layout/filesize.go (88.9%)</option>
<option value="file13">github.com/bengarrett/sauce/internal/layout/filetype.go (100.0%)</option>
<option value="file14">github.com/bengarrett/sauce/internal/layout/info.go (97.2%)</option>
<option value="file15">github.com/bengarrett/sauce/internal/layout/layout.go (88.1%)</option>
<option value="file16">github.com/bengarrett/sauce/internal/layout/none.go (100.0%)</option>
<option value="file17">github.com/bengarrett/sauce/internal/layout/vector.go (100.0%)</option>
<option value="file18">github.com/bengarrett/sauce/internal/layout/xbin.go (100.0%)</option>
<option value="file19">github.com/bengarrett/sauce/sauce.go (80.9%)</option>
</select>
</div>
<div id="legend">
<span>not tracked</span>
<span class="cov0">not covered</span>
<span class="cov8">covered</span>
</div>
</div>
<div id="content">
<pre class="file" id="file0" style="display: none">// The code in humanize/bytes.go is derived from [labstack/gommon], Common packages for Go
//
// [The MIT License] (MIT) Copyright (c) 2018 labstack
//
// [labstack/gommon]: https://github.com/labstack/gommon
// [The MIT License]: https://github.com/labstack/gommon/blob/master/LICENSE
// Package humanize is parses some limited time and byte sizes data to human readable formats.
package humanize
import (
"golang.org/x/text/language"
"golang.org/x/text/message"
)
const (
_ = 1.0 << (binaryBase * iota)
kib
mib
gib
tib
pib
oneDecimalPoint = "%.1f %s"
twoDecimalPoints = "%.2f %s"
binaryBase = 10
kb = 1000
mb = kb * kb
gb = mb * kb
tb = gb * kb
pb = tb * kb
)
// Binary formats the bytes integer to localized, readable string using binary units of measure.
func Binary(b int64, t language.Tag) string <span class="cov8" title="1">{
p := message.NewPrinter(t)
value := float64(b)
var multiple string
switch </span>{
case b >= pib:<span class="cov8" title="1">
value /= pib
multiple = "PiB"</span>
case b >= tib:<span class="cov8" title="1">
value /= tib
multiple = "TiB"</span>
case b >= gib:<span class="cov8" title="1">
value /= gib
multiple = "GiB"</span>
case b >= mib:<span class="cov8" title="1">
value /= mib
multiple = "MiB"</span>
case b >= kib:<span class="cov8" title="1">
value /= kib
return p.Sprintf(oneDecimalPoint, value, "KiB")</span>
case b == 0:<span class="cov8" title="1">
return "0"</span>
default:<span class="cov8" title="1">
return p.Sprintf("%dB", b)</span>
}
<span class="cov8" title="1">return p.Sprintf(twoDecimalPoints, value, multiple)</span>
}
// Decimal formats the bytes integer to localized readable string using decimal units of measure.
func Decimal(b int64, t language.Tag) string <span class="cov8" title="1">{
p := message.NewPrinter(t)
value := float64(b)
var multiple string
switch </span>{
case b >= pb:<span class="cov8" title="1">
value /= pb
multiple = "PB"</span>
case b >= tb:<span class="cov8" title="1">
value /= tb
multiple = "TB"</span>
case b >= gb:<span class="cov8" title="1">
value /= gb
multiple = "GB"</span>
case b >= mb:<span class="cov8" title="1">
value /= mb
multiple = "MB"</span>
case b >= kb:<span class="cov8" title="1">
value /= kb
return p.Sprintf(oneDecimalPoint, value, "kB")</span>
case b == 0:<span class="cov8" title="1">
return "0"</span>
default:<span class="cov8" title="1">
return p.Sprintf("%dB", b)</span>
}
<span class="cov8" title="1">return p.Sprintf(twoDecimalPoints, value, multiple)</span>
}
</pre>
<pre class="file" id="file1" style="display: none">package humanize
import (
"time"
)
// Layout is a predefined time format.
type Layout string
// Date and time layouts.
const (
DMY Layout = "2 Jan 2006" // day month year
YMD Layout = "2006 Jan 2" // year month day
MDY Layout = "Jan 2 2006" // month day year
H12 Layout = "3:04 pm" // 12 hour clock
H24 Layout = "15:04" // 24 hour clock
)
// Date with time layouts.
const (
DMY12 Layout = DMY + " " + H12 // 2 Jan 2006 3:04 pm
DMY24 Layout = DMY + " " + H24 // 2 Jan 2006 15:04
YMD12 Layout = YMD + " " + H12 // 2006 Jan 2 3:04 pm
YMD24 Layout = YMD + " " + H24 // 2006 Jan 2 15:04
MDY12 Layout = MDY + " " + H12 // Jan 2 2006 3:04 pm
MDY24 Layout = MDY + " " + H24 // Jan 2 2006 15:04
)
// Format returns the time using the predefined layout.
func (l Layout) Format(t time.Time) string <span class="cov8" title="1">{
switch l </span>{
case "":<span class="cov8" title="1">
return t.Format(string(YMD24))</span>
case DMY, YMD, MDY, H12, H24, DMY12, DMY24, YMD12, YMD24, MDY12, MDY24:<span class="cov8" title="1">
return t.Format(string(l))</span>
default:<span class="cov8" title="1">
return ""</span>
}
}
</pre>
<pre class="file" id="file2" style="display: none">package layout
import (
"errors"
"fmt"
"strings"
)
// ANSIFlags allow an author of ANSi and similar files to provide a clue to a viewer / editor
// how to render the image. The 8 bits in the ANSiFlags contain the following information:
// 0 0 0 A R L S B
// B: Non-blink mode (iCE Color).
// LS: Letter-spacing (a.k.a. 8/9 pixel font selection).
// AR: Aspect Ratio.
// See http://www.acid.org/info/sauce/sauce.htm#ANSiFlags.
var ErrInvalid = errors.New("invalid value")
// Unsupported is a legacy value used by Letter-spacing and Aspect Ratio.
// It acts as an unsupported placeholder for SAUCE versions prior to v00.5 from Nov 2013.
const Unsupported = "no preference"
// Flags is the SAUCE Flags field.
type Flags uint8
// ANSIFlags allow an author of ANSi and similar files to provide a clue to a viewer/editor how to render the image.
type ANSIFlags struct {
Decimal Flags `json:"decimal" xml:"decimal,attr"` // decimal, unsigned integer flags value
Binary string `json:"binary" xml:"binary,attr"` // binary notation flags value
B ANSIFlagB `json:"nonBlinkMode" xml:"non_blink_mode"` // b is the non-blink "iCE Color" toggle
LS ANSIFlagLS `json:"letterSpacing" xml:"letter_spacing"` // ls is the letter-spacing value
AR ANSIFlagAR `json:"aspectRatio" xml:"aspect_ratio"` // ar is the aspect ratio value
Interpretations string `json:"-" xml:"-"` // interpretations are humanized descriptions of the bits
}
func (a *ANSIFlags) String() string <span class="cov8" title="1">{
if a.Decimal == 0 </span><span class="cov8" title="1">{
return ""
}</span>
<span class="cov8" title="1">b, ls, ar := a.B.Info, a.LS.Info, a.AR.Info
s := []string{}
if b != Unsupported </span><span class="cov8" title="1">{
s = append(s, b)
}</span>
<span class="cov8" title="1">if ls != Unsupported </span><span class="cov8" title="1">{
s = append(s, ls)
}</span>
<span class="cov8" title="1">if ar != Unsupported </span><span class="cov8" title="1">{
s = append(s, ar)
}</span>
<span class="cov8" title="1">empty := strings.TrimSpace(strings.Join(s, "")) == ""
if empty </span><span class="cov0" title="0">{
return ""
}</span>
<span class="cov8" title="1">return strings.Join(s, ", ")</span>
}
// ANSIFlagB is the interpretation of the SAUCE Flags non-blink mode binary bit.
type ANSIFlagB struct {
Flag BBit `json:"flag" xml:"flag"` // flag the non-blink "iCE Color" toggle
Info string `json:"interpretation" xml:"interpretation,attr"` // info description of the toggle
}
func (f Flags) Parse() ANSIFlags <span class="cov8" title="1">{
const binary5Bits, minLen = "%05b", 5
bin := fmt.Sprintf(binary5Bits, f)
r := []rune(bin)
if len(r) < minLen </span><span class="cov0" title="0">{
return ANSIFlags{
Decimal: f,
Binary: bin,
}
}</span>
<span class="cov8" title="1">b, ls, ar := string(r[0]), string(r[1:3]), string(r[3:5])
return ANSIFlags{
Decimal: f,
Binary: bin,
B: ANSIFlagB{Flag: BBit(b), Info: BBit(b).String()},
LS: ANSIFlagLS{Flag: LsBit(ls), Info: LsBit(ls).String()},
AR: ANSIFlagAR{Flag: ArBit(ar), Info: ArBit(ar).String()},
}</span>
}
// ANSIFlagLS is the interpretation of the SAUCE Flags letter spacing binary bits.
type ANSIFlagLS struct {
Flag LsBit `json:"flag" xml:"flag"` // lsbit letter-spacing value
Info string `json:"interpretation" xml:"interpretation,attr"` // info description of the value
}
type LsBit string // Letter-spacing two bit value.
func (ls LsBit) String() string <span class="cov8" title="1">{
const none, eight, nine = "00", "01", "10"
switch ls </span>{
case none:<span class="cov8" title="1">
return Unsupported</span>
case eight:<span class="cov8" title="1">
return "select 8 pixel font"</span>
case nine:<span class="cov8" title="1">
return "select 9 pixel font"</span>
default:<span class="cov8" title="1">
return ErrInvalid.Error()</span>
}
}
// ANSIFlagAR is the interpretation of the SAUCE Flags aspect ratio binary bits.
type ANSIFlagAR struct {
Flag ArBit `json:"flag" xml:"flag"` // ar aspect ratio value
Info string `json:"interpretation" xml:"interpretation,attr"` // info description of the value
}
// ArBit is the Aspect Ratio two bit value.
type ArBit string
func (ar ArBit) String() string <span class="cov8" title="1">{
const none, strect, square = "00", "01", "10"
switch ar </span>{
case none:<span class="cov8" title="1">
return Unsupported</span>
case strect:<span class="cov8" title="1">
return "stretch pixels"</span>
case square:<span class="cov8" title="1">
return "square pixels"</span>
default:<span class="cov8" title="1">
return ErrInvalid.Error()</span>
}
}
// BBit is the non-blink "iCE Color" bit value.
type BBit string
func (b BBit) String() string <span class="cov8" title="1">{
const blink, non = "0", "1"
switch b </span>{
case blink:<span class="cov8" title="1">
return "blink mode"</span>
case non:<span class="cov8" title="1">
return "non-blink mode"</span>
default:<span class="cov8" title="1">
return ErrInvalid.Error()</span>
}
}
</pre>
<pre class="file" id="file3" style="display: none">package layout
// An archive file data type.
// See http://www.acid.org/info/sauce/sauce.htm#FileType
// Archive and compressed files.
type Archive uint
const (
Zip Archive = iota
Arj
Lzh
Arc
Tar
Zoo
Rar
Uc2
Pak
Sqz
)
func (a Archive) String() string <span class="cov8" title="1">{
if (a) > (Sqz) </span><span class="cov8" title="1">{
return ""
}</span>
<span class="cov8" title="1">return [...]string{
"ZIP compressed archive",
"ARJ compressed archive",
"LHA compressed archive",
"ARC compressed archive",
"Tarball tape archive",
"ZOO compressed archive",
"RAR compressed archive",
"UltraCompressor II compressed archive",
"PAK ARC compressed archive",
"Squeeze It compressed archive",
}[a]</span>
}
</pre>
<pre class="file" id="file4" style="display: none">package layout
// An audio file data type.
// See http://www.acid.org/info/sauce/sauce.htm#FileType
// Audio or music files.
type Audio uint
const (
Mod Audio = iota
Composer669
Stm
S3m
Mtm
Far
Ult
Amf
Dmf
Okt
Rol
Cmf
Midi
Sadt
Voc
Wave
Smp8
Smp8s
Smp16
Smp16s
Patch8
Patch16
Xm
Hsc
It
)
func (a Audio) String() string <span class="cov8" title="1">{
if a > It </span><span class="cov8" title="1">{
return ""
}</span>
<span class="cov8" title="1">return [...]string{
"NoiseTracker module",
"Composer 669 module",
"ScreamTracker module",
"ScreamTracker 3 module",
"MultiTracker module",
"Farandole Composer module",
"Ultra Tracker module",
"Dual Module Player module",
"X-Tracker module",
"Oktalyzer module",
"AdLib Visual Composer FM audio",
"Creative Music FM audio",
"MIDI audio",
"SAdT composer FM audio",
"Creative Voice File",
"Waveform audio",
"single channel 8-bit sample",
"stereo 8-bit sample",
"single channel 16-bit sample",
"stereo 16-bit sample",
"8-bit patch file",
"16-bit patch file",
"Extended Module",
"Hannes Seifert Composition FM audio",
"Impulse Tracker module",
}[a]</span>
}
func (ti *Infos) audio(ft uint8) <span class="cov8" title="1">{
switch Audio(ft) </span>{
case Smp8, Smp8s, Smp16, Smp16s:<span class="cov8" title="1">
ti.Info1.Info = "sample rate"</span>
case Mod, Composer669, Stm, S3m, Mtm, Far, Ult, Amf, Dmf, Okt,
Rol, Cmf, Midi, Sadt, Voc, Wave, Patch8, Patch16, Xm, Hsc, It:<span class="cov0" title="0">
return</span>
}
}
</pre>
<pre class="file" id="file5" style="display: none">package layout
// This is a raw memory copy of a text mode screen. Also known as a .BIN file.
// This is essentially a collection of character and attribute pairs.
// See http://www.acid.org/info/sauce/sauce.htm#FileType
// BinaryText is a raw memory copy of a text mode screen.
type BinaryText uint
const (
BinaryScreenImage BinaryText = iota
)
func (b BinaryText) String() string <span class="cov8" title="1">{
if b > BinaryScreenImage </span><span class="cov8" title="1">{
return ""
}</span>
<span class="cov8" title="1">return [...]string{
"Binary text or a .BIN file",
}[b]</span>
}
</pre>
<pre class="file" id="file6" style="display: none">package layout
// Bitmap graphic and animation files.
// See http://www.acid.org/info/sauce/sauce.htm#FileType
// Bitmap graphic and animation files.
type Bitmap uint
const (
Gif Bitmap = iota
Pcx
Lbm
Tga
Fli
Flc
Bmp
Gl
Dl
Wpg
Png
Jpg
Mpg
Avi
)
func (b Bitmap) String() string <span class="cov8" title="1">{
if b > Avi </span><span class="cov8" title="1">{
return ""
}</span>
<span class="cov8" title="1">return [...]string{
"GIF image",
"ZSoft Paintbrush image",
"DeluxePaint image",
"Targa true color image",
"Autodesk Animator animation",
"Autodesk Animator animation",
"BMP Windows/OS2 bitmap",
"Grasp GL animation",
"DL animation",
"WordPerfect graphic",
"PNG image",
"Jpeg photo",
"MPEG video",
"AVI video",
}[b]</span>
}
</pre>
<pre class="file" id="file7" style="display: none">package layout
// A character based file. These files are typically interpreted sequentially.
// Also known as streams.
// See http://www.acid.org/info/sauce/sauce.htm#FileType
// Character files more commonly referred as text files.
type Character uint
const (
ASCII Character = iota
Ansi
AnsiMation
RipScript
PCBoard
Avatar
HTML
Source
TundraDraw
)
func (c Character) String() string <span class="cov8" title="1">{
if c > TundraDraw </span><span class="cov8" title="1">{
return ""
}</span>
<span class="cov8" title="1">return [...]string{
"ASCII text",
"ANSI color text",
"ANSIMation",
"RIPScript",
"PCBoard color text",
"Avatar color text",
"HTML markup",
"Programming source code",
"TundraDraw color text",
}[c]</span>
}
// Desc is the character description.
func (c Character) Desc() string <span class="cov8" title="1">{
if c > TundraDraw </span><span class="cov8" title="1">{
return ""
}</span>
<span class="cov8" title="1">return [...]string{
"ASCII text file with no formatting codes or color codes.",
"ANSI text file with coloring codes and cursor positioning.",
"ANSIMation are ANSI text files that rely on fixed screen sizes.",
"RIPScript are Remote Imaging Protocol graphics.",
"PCBoard color codes and macros, and ANSI codes.",
"Avatar color codes, and ANSi codes.",
"HTML markup files.",
"Source code for a programming language.",
"TundraDraw files, like ANSI, but with a custom palette.",
}[c]</span>
}
func (d *Layout) Description() string <span class="cov8" title="1">{
dt := UnsignedBinary1(d.Datatype)
ft := UnsignedBinary1(d.Filetype)
chr := Character(ft)
if TypeOfData(dt) != Characters </span><span class="cov8" title="1">{
return ""
}</span>
<span class="cov8" title="1">switch chr </span>{
case ASCII,
Ansi,
AnsiMation,
RipScript,
PCBoard,
Avatar,
HTML,
Source,
TundraDraw:<span class="cov8" title="1">
return chr.Desc()</span>
}
<span class="cov0" title="0">return ""</span>
}
</pre>
<pre class="file" id="file8" style="display: none">package layout
import (
"bufio"
"bytes"
"strings"
)
// A SAUCE comment block is an optional, variable sized structure that holds up to 255 lines
// of additional information, each line 64 characters wide. There are as many comment lines
// as is mentioned in the Comments field of the SAUCE record.
// If the Comments field is set to 0, there should not be a comment block at all.
// See http://www.acid.org/info/sauce/sauce.htm
type Comnt struct {
Index int // index is the calculated starting position of the comment block
Length int // length is the calculated length of the comment block
Count Comments // count are the reported number of lines in the SAUCE comment block
Lines []byte // lines of text
}
// Comment contains the optional SAUCE comment block.
// A SAUCE comment block is an optional, variable sized structure that holds
// up to 255 lines of additional information, each line 64 characters wide.
type Comment struct {
ID string `json:"id" xml:"id,attr"` // id is the SAUCE comment block identification, this should be "COMNT"
Count int `json:"count" xml:"count,attr"` // count are the reported number of lines in the SAUCE comment block
Index int `json:"-" xml:"-"` // index are the calculated starting position of the comment block
Comment []string `json:"lines" xml:"line"` // comment value, each comment line should be comprised of 64 characters
}
// CommentBlock parses the optional SAUCE comment block.
func (d *Layout) CommentBlock() Comment <span class="cov8" title="1">{
breakCount := len(strings.Split(string(d.Comnt.Lines), "\n"))
var c Comment
c.ID = ComntID
c.Count = int(UnsignedBinary1(d.Comnt.Count))
c.Index = -1
if d.Comnt.Index > 0 </span><span class="cov0" title="0">{
c.Index = d.Comnt.Index - len(ComntID)
}</span>
<span class="cov8" title="1">if breakCount > 0 </span><span class="cov8" title="1">{
// comments with line breaks are technically invalid but they exist in the wild.
// https://github.com/16colo-rs/16c/issues/67
c.Comment = CommentByBreak(d.Comnt.Lines)
return c
}</span>
<span class="cov0" title="0">c.Comment = CommentByLine(d.Comnt.Lines)
return c</span>
}
// CommentByBreak parses the SAUCE comment by line break characters.
func CommentByBreak(b []byte) []string <span class="cov8" title="1">{
if len(b) == 0 </span><span class="cov8" title="1">{
return []string{}
}</span>
<span class="cov8" title="1">r := bytes.NewReader(b)
scanner := bufio.NewScanner(r)
s := []string{}
for scanner.Scan() </span><span class="cov8" title="1">{
s = append(s, scanner.Text())
}</span>
<span class="cov8" title="1">return s</span>
}
// CommentByLine parses the SAUCE comment by lines of 64 characters.
func CommentByLine(b []byte) []string <span class="cov8" title="1">{
if len(b) == 0 </span><span class="cov8" title="1">{
return []string{}
}</span>
<span class="cov8" title="1">s, l := "", 0
resetLine := func() </span><span class="cov8" title="1">{
s, l = "", 0
}</span>
<span class="cov8" title="1">lines := []string{}
for _, c := range b </span><span class="cov8" title="1">{
l++
s += string(c)
if l == ComntLineSize </span><span class="cov8" title="1">{
lines = append(lines, s)
resetLine()
}</span>
}
<span class="cov8" title="1">return lines</span>
}
</pre>
<pre class="file" id="file9" style="display: none">package layout
// Type of data. SAUCE supports 8 different types and an undefined value.
// See http://www.acid.org/info/sauce/sauce.htm
// Datas is the SAUCE DataType value and name.
type Datas struct {
Type TypeOfData `json:"type" xml:"type"` // typeofdata is the unsigned data type
Name string `json:"name" xml:"name"` // name of the data type
}
// TypeOfData is the SAUCE DataType.
type TypeOfData uint
const (
Nones TypeOfData = iota // undefined filetype
Characters // characters and plain text based files
Bitmaps // bitmap, graphic and animation files
Vectors // vector graphic files
Audios // audio and sound files
BinaryTexts // binary texts that are raw memory copies of a text mode screen, also known as a 'bin' file
XBins // xbin or extended bin file
Archives // archived file such as a zip package
Executables // executable file that is an application or program launcher
)
func (d TypeOfData) String() string <span class="cov8" title="1">{
if d > Executables </span><span class="cov8" title="1">{
return ""
}</span>
<span class="cov8" title="1">return [...]string{
"undefined",
"text or character stream",
"bitmap graphic or animation",
"vector graphic",
"audio or music",
"binary text",
"extended binary text",
"archive",
"executable",
}[d]</span>
}
func (d *Layout) DataType() Datas <span class="cov8" title="1">{
dt := UnsignedBinary1(d.Datatype)
return Datas{
Type: TypeOfData(dt),
Name: TypeOfData(dt).String(),
}
}</span>
</pre>
<pre class="file" id="file10" style="display: none">package layout
import (
"errors"
"fmt"
"log"
"strconv"
"time"
)
// The date the file was created. The format for the date is CCYYMMDD (century, year, month, day).
// Example: 4 May 2013 would be stored as "20130504".
// See http://www.acid.org/info/sauce/sauce.htm
var (
ErrParseDate = errors.New("parse date to integer conversion")
ErrSauceDate = errors.New("sauce date error")
)
// Dates is the date the file was created, in multiple time formats.
type Dates struct {
Value string `json:"value" xml:"value"` // date format using CCYYMMDD (century, year, month, day)
Time time.Time `json:"iso" xml:"date"` // time as a go time type
Epoch int64 `json:"epoch" xml:"epoch,attr"` // epoch unix time, is the number of seconds since 1 Jan 1970
}
func (d *Layout) Dates() Dates <span class="cov8" title="1">{
tt, err := d.date()
if err != nil </span><span class="cov8" title="1">{
log.Printf("%s: %s\n", ErrSauceDate, err)
return Dates{}
}</span>
<span class="cov8" title="1">epoch := tt.Unix()
return Dates{
Value: d.Date.String(),
Time: tt,
Epoch: epoch,
}</span>
}
func (d *Layout) date() (time.Time, error) <span class="cov8" title="1">{
dd := d.Date
year, err := strconv.Atoi(string(dd[0:4]))
if err != nil </span><span class="cov8" title="1">{
return time.Time{},
fmt.Errorf("year failed: %v: %w", year, ErrParseDate)
}</span>
<span class="cov8" title="1">month, err := strconv.Atoi(string(dd[4:6]))
if err != nil </span><span class="cov0" title="0">{
return time.Time{},
fmt.Errorf("month failed: %v: %w", month, ErrParseDate)
}</span>
<span class="cov8" title="1">day, err := strconv.Atoi(string(dd[6:8]))
if err != nil </span><span class="cov0" title="0">{
return time.Time{},
fmt.Errorf("day failed: %v: %w", day, ErrParseDate)
}</span>
<span class="cov8" title="1">return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC), nil</span>
}
</pre>
<pre class="file" id="file11" style="display: none">package layout
// A executable file. Any executable file. .exe, .dll, .bat, ...
// Executable scripts such as .vbs should be tagged as Source.
// See http://www.acid.org/info/sauce/sauce.htm#FileType
// Executable program files.
type Executable uint
const (
Exe Executable = iota
)
func (e Executable) String() string <span class="cov8" title="1">{
if e > Exe </span><span class="cov8" title="1">{
return ""
}</span>
<span class="cov8" title="1">return [...]string{
"Executable program file",
}[e]</span>
}
</pre>
<pre class="file" id="file12" style="display: none">package layout
import (
"bytes"
"encoding/binary"
"log"
"github.com/bengarrett/sauce/humanize"
"golang.org/x/text/language"
)
// Sizes is the original file size in multiple formats.
type Sizes struct {
Bytes uint16 `json:"bytes" xml:"bytes"` // bytes as an integer
Decimal string `json:"decimal" xml:"decimal,attr"` // decimal is a base 10 value
Binary string `json:"binary" xml:"binary,attr"` // binary is a base 2 value
}
func (d *Layout) Sizes() Sizes <span class="cov8" title="1">{
value := UnsignedBinary4(d.Filesize)
en := language.English
return Sizes{
Bytes: value,
Decimal: humanize.Decimal(int64(value), en),
Binary: humanize.Binary(int64(value), en),
}
}</span>
func UnsignedBinary4(b [4]byte) uint16 <span class="cov8" title="1">{
var data uint16
buf := bytes.NewReader(b[:])
err := binary.Read(buf, binary.LittleEndian, &data)
if err != nil </span><span class="cov0" title="0">{
log.Println("unsigned 4 byte, LE binary failed:", err)
}</span>
<span class="cov8" title="1">return data</span>
}
</pre>
<pre class="file" id="file13" style="display: none">package layout
import "errors"
// Type of file.
// See http://www.acid.org/info/sauce/sauce.htm#FileType
var ErrFileType = errors.New("unknown filetype")
// Files is the SAUCE FileType value and name.
type Files struct {
Type TypeOfFile `json:"type" xml:"type"` // type of file unsigned integer
Name string `json:"name" xml:"name"` // name of the file type
}
// TypeOfFile is the SAUCE FileType.
type TypeOfFile uint
func (d *Layout) FileType() Files <span class="cov8" title="1">{
data := UnsignedBinary1(d.Datatype)
file := UnsignedBinary1(d.Filetype)
switch TypeOfData(data) </span>{
case Nones:<span class="cov8" title="1">
n := None(file)
return Files{TypeOfFile(n), n.String()}</span>
case Characters:<span class="cov8" title="1">
c := Character(file)
return Files{TypeOfFile(c), c.String()}</span>
case Bitmaps:<span class="cov8" title="1">
b := Bitmap(file)
return Files{TypeOfFile(b), b.String()}</span>
case Vectors:<span class="cov8" title="1">
v := Vector(file)
return Files{TypeOfFile(v), v.String()}</span>
case Audios:<span class="cov8" title="1">
a := Audio(file)
return Files{TypeOfFile(a), a.String()}</span>
case BinaryTexts:<span class="cov8" title="1">
b := BinaryText(file)
return Files{TypeOfFile(b), b.String()}</span>
case XBins:<span class="cov8" title="1">
x := XBin(file)
return Files{TypeOfFile(x), x.String()}</span>
case Archives:<span class="cov8" title="1">
a := Archive(file)
return Files{TypeOfFile(a), a.String()}</span>
case Executables:<span class="cov8" title="1">
e := Executable(file)
return Files{TypeOfFile(e), e.String()}</span>
default:<span class="cov8" title="1">
var empty TypeOfFile
return Files{empty, ErrFileType.Error()}</span>
}
}
</pre>
<pre class="file" id="file14" style="display: none">package layout
import (
"bytes"
"encoding/binary"
"log"
)
// Infos includes the SAUCE fields dependant on both DataType and FileType.
type Infos struct {
// Info1 dependant numeric information field 1.
Info1 Info `json:"1" xml:"type1"`
// Info2 dependant numeric information field 2.
Info2 Info `json:"2" xml:"type2"`
// Info3 dependant numeric information field 3.
Info3 Info `json:"3" xml:"type3"`
// Flags are file type dependant flags.
Flags ANSIFlags `json:"flags" xml:"flags"`
// Font field allows an author to provide a clue to the viewer/editor which font to use to render the image.
Font string `json:"fontName" xml:"fontname"`
}
// Info is the type for the SAUCE TInfo1, TInfo2, TInfo3 and TInfo4 fields.
type Info struct {
// Value of the field.
Value uint16 `json:"value" xml:"value"`