An open API service indexing awesome lists of open source software.

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.

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 follows

go 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

## Contributors

To 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.