https://github.com/samcrosoft/magic
A Golang package that validates the content of a byte array to a file type. It is a basic but very useful package, especially when you are accepting uploads from your users and you want to be sure the content is valid.
https://github.com/samcrosoft/magic
Last synced: 3 months ago
JSON representation
A Golang package that validates the content of a byte array to a file type. It is a basic but very useful package, especially when you are accepting uploads from your users and you want to be sure the content is valid.
- Host: GitHub
- URL: https://github.com/samcrosoft/magic
- Owner: samcrosoft
- License: mit
- Created: 2015-05-16T18:56:39.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-05-17T16:57:30.000Z (about 10 years ago)
- Last Synced: 2025-01-29T12:30:15.868Z (4 months ago)
- Language: Go
- Size: 195 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# magic
This is a simple GoLang package that validates the content of a byte array to a file type. The need for this package became evident when I needed to validate a byte array as a png file
to then forwarded to a waveform point extractor.------
Installation
============
To install magic, you can `go get` this like you do any other go package as followsgo get github.com/samcrosoft/magic
------Example
============Want to see how simple it is to use this package,
```Go
sImagePath := "./corpus/image/png-sample.png"
if oBytes, err := ioutil.ReadFile(sImagePath); err == nil{
oType := &types.PNGType{}
if bValid, oErr := IsBytesContentAValidType(oBytes, oType); bValid == true{
// then image is a valid png
}
}
```At the moment, there are a couple of image type formats
1. types.PNGType
2. types.JPEGType## Tests
To run the tests, just run go tests
## ContributorsTo Contribute to this project is just simple, fork the project, create a new filetype with a unique magic number identifying the file type and commit it.
## License
This is licensed in MIT, you can do everything you want with it, just give a shoutout if you can.