Skip to content

Commit a70c3a9

Browse files
committedJan 9, 2021
Clean things up and update code
Signed-off-by: Krzysztof Wilczyński <[email protected]>
1 parent e8f6cff commit a70c3a9

14 files changed

+2033
-2124
lines changed
 

‎COPYRIGHT

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Copyright 2013-2020 Krzysztof Wilczyński
1+
Copyright 2013-2021 Krzysztof Wilczyński

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Krzysztof Wilczyński (<kw@linux.com>)
3333

3434
## Copyright
3535

36-
Copyright 2013-2020 Krzysztof Wilczyński
36+
Copyright 2013-2021 Krzysztof Wilczyński
3737

3838
## License
3939

‎common.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ extern "C" {
4545
#endif
4646

4747
#if !defined(MAGIC_NO_CHECK_CSV)
48-
# define MAGIC_NO_CHECK_CSV -1
48+
# define MAGIC_NO_CHECK_CSV 0
4949
#endif
5050

5151
#if !defined(MAGIC_NO_CHECK_JSON)
52-
# define MAGIC_NO_CHECK_JSON -1
52+
# define MAGIC_NO_CHECK_JSON 0
5353
#endif
5454

5555
#if defined(MAGIC_VERSION) && MAGIC_VERSION >= 532

‎constants_test.go

+17-34
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,40 @@
11
package magic
22

3-
import (
4-
"testing"
5-
)
3+
import "testing"
64

75
func TestConstants(t *testing.T) {
86
var constantTests = []struct {
97
given int
10-
expected []int
8+
expected int
119
}{
1210
{
1311
MIME,
14-
[]int{
15-
MIME_TYPE,
16-
MIME_ENCODING,
17-
},
12+
MIME_TYPE | MIME_ENCODING,
1813
},
1914
{
2015
NO_CHECK_ASCII,
21-
[]int{
22-
NO_CHECK_TEXT,
23-
},
16+
NO_CHECK_TEXT,
17+
},
18+
{
19+
NO_CHECK_FORTRAN,
20+
0,
21+
},
22+
{
23+
NO_CHECK_TROFF,
24+
0,
2425
},
2526
{
2627
NO_CHECK_BUILTIN,
27-
[]int{
28-
NO_CHECK_COMPRESS,
29-
NO_CHECK_TAR,
30-
NO_CHECK_APPTYPE,
31-
NO_CHECK_ELF,
32-
NO_CHECK_TEXT,
33-
NO_CHECK_CSV,
34-
NO_CHECK_CDF,
35-
NO_CHECK_TOKENS,
36-
NO_CHECK_ENCODING,
37-
NO_CHECK_JSON,
38-
},
28+
NO_CHECK_COMPRESS | NO_CHECK_TAR | NO_CHECK_APPTYPE | NO_CHECK_ELF | NO_CHECK_TEXT | NO_CHECK_CSV | NO_CHECK_CDF | NO_CHECK_TOKENS | NO_CHECK_ENCODING | NO_CHECK_JSON,
3929
},
4030
}
4131

4232
for _, tt := range constantTests {
43-
expected := 0
44-
for _, flag := range tt.expected {
45-
if flag > -1 {
46-
expected |= flag
47-
}
48-
}
49-
50-
if tt.given != expected {
51-
t.Errorf("value given 0x%x, want 0x%x", tt.given, expected)
33+
if tt.given != tt.expected {
34+
t.Errorf("value given 0x%x, want 0x%x", tt.given, tt.expected)
5235
}
5336
}
5437
}
5538

56-
func TestParameters(t *testing.T) {
57-
}
39+
// func TestParameters(t *testing.T) {
40+
// }

‎example_package_test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import (
88
)
99

1010
// This example shows how to use the Separator to split results
11-
// when the CONTINUE flag is set and more than one match was
11+
// when the "CONTINUE" flag is set and more than one match was
1212
// returned by the Magic library.
1313
func Example_separator() {
1414
buffer := []byte("#!/bin/bash\n\n")
1515

16-
// Open and load default Magic database ...
16+
// Open and load the default Magic database.
1717
m, err := magic.New()
1818
if err != nil {
19-
panic(fmt.Sprintf("An error occurred: %s\n", err))
19+
panic(fmt.Sprintf("An has error occurred: %s\n", err))
2020
}
2121

2222
m.SetFlags(magic.CONTINUE)
@@ -29,35 +29,35 @@ func Example_separator() {
2929
for _, s := range strings.Split(result, magic.Separator) {
3030
fmt.Printf("\t%s\n", s)
3131
}
32-
3332
m.Close()
34-
// Should output:
33+
// Output:
3534
// Matches for data in the buffer are:
36-
// Bourne-Again shell script text executable
37-
// a /bin/bash script, ASCII text executable
35+
// Bourne-Again shell script text executable
36+
// a /bin/bash script, ASCII text executable
3837
}
3938

4039
// This example shows how to use Open together with a closure.
4140
func Example_closure() {
4241
var s string
4342

4443
// When using magic.Open you don't have to worry
45-
// about closing the underlying Magic database.
44+
// about closing the the Magic database.
4645
err := magic.Open(func(m *magic.Magic) error {
4746
m.SetFlags(magic.MIME)
4847
mime, err := m.File("test/fixtures/gopher.png")
4948
if err != nil {
5049
return err // Propagate error outside of the closure.
5150
}
52-
s = mime // Pass results outside ...
51+
s = mime // Pass results outside.
5352
return nil
5453
})
55-
5654
if err != nil {
57-
panic(fmt.Sprintf("An error occurred: %s\n", err))
55+
panic(fmt.Sprintf("An has error occurred: %s\n", err))
5856
}
59-
6057
fmt.Printf("File MIME type is: %s\n", s)
6158
// Output:
6259
// File MIME type is: image/png; charset=binary
6360
}
61+
62+
// func Example_disable_autoload() {
63+
// }

‎example_test.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import (
77
)
88

99
// This example show the basic usage of the package: Open and initialize
10-
// Magic library, set appropriate flags, for a given file find its MIME
11-
// identification (as per the flag set), print the results and close
10+
// the Magic library, set appropriate flags, for a given file find its
11+
// MIME identification (as per the flag set), print the results and close
1212
// releasing all initialized resources.
1313
func Example_basic() {
14-
// Open and load default Magic database ...
14+
// Open and load the default Magic database.
1515
m, err := magic.New()
1616
if err != nil {
17-
panic(fmt.Sprintf("An error occurred: %s\n", err))
17+
panic(fmt.Sprintf("An has error occurred: %s\n", err))
1818
}
1919

2020
m.SetFlags(magic.MIME)
@@ -31,9 +31,12 @@ func Example_basic() {
3131

3232
// This example shows how to quickly find MIME type for a file.
3333
func ExampleFileType() {
34+
// The magic.FileType function will open the Magic database,
35+
// set flags to "MIME", return the result, and then close
36+
// the Magic database afterwards.
3437
mime, err := magic.FileType("test/fixtures/gopher.png")
3538
if err != nil {
36-
panic(fmt.Sprintf("An error occurred: %s\n", err))
39+
panic(fmt.Sprintf("An has error occurred: %s\n", err))
3740
}
3841
fmt.Printf("File MIME type is: %s\n", mime)
3942
// Output:
@@ -46,7 +49,7 @@ func ExampleBufferEncoding() {
4649

4750
mime, err := magic.BufferEncoding(buffer)
4851
if err != nil {
49-
panic(fmt.Sprintf("An error occurred: %s\n", err))
52+
panic(fmt.Sprintf("An has error occurred: %s\n", err))
5053
}
5154
fmt.Printf("Data in the buffer is encoded as: %s\n", mime)
5255
// Output:

‎magic.go

+271-301
Large diffs are not rendered by default.

‎magic_test.go

+1,720-1,731
Large diffs are not rendered by default.

‎test/fixtures/old-format/png-broken.magic

-12
This file was deleted.

‎test/fixtures/old-format/png-fake.magic

-12
This file was deleted.

‎test/fixtures/old-format/png.magic

-12
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)
Please sign in to comment.