Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/Defacto2/magicnumber

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/Defacto2/magicnumber

  • v1.0.5
  • Source
  • Go
  • Socket score

Version published
Created
Source

Defacto2 / magicnumber

Go Reference Go Report Card

The magicnumber package is to read the bytes within a file to learn of the format or type of file. This is useful for identifying the file without relying on the file extension or MIME type. See the reference documentation for additional usage and examples.

package main

import (
    "fmt"
    "log"
    "os"

    "github.com/Defacto2/magicnumber"
)

func main() {
    file, err := os.Open("example.exe")
    if err != nil {
        log.Fatal(err)
    }
    defer file.Close()

    mn, err := magicnumber.Find(file)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("File type: %s\n", mn.Type)
    fmt.Printf("File extension: %s\n", mn.Extension)
}

FAQs

Package last updated on 22 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc