New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

file_type_detector_sfedu

Package Overview
Dependencies
Maintainers
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file_type_detector_sfedu

  • 0.2.2
  • Rubygems
  • Socket score

Version published
Maintainers
4
Created
Source

file_type_detector_sfedu

file_type_detector_sfedu is a Ruby gem that allows you to determine the type of files based on their extension or content.

Installation

Add this gem to your Gemfile and run bundle install:

gem "file_type_detector_sfedu"

Alternatively, install it directly using the gem command:

gem install file_type_detector_sfedu

Usage

To use the gem, you need to call the check method with a parameter in the form of a file path:

require "file_type_detector_sfedu"

puts FileTypeDetector.check("path/to/your/file.pdf") # if it's truly pdf, value will be true, unless - false

check method will automatically detect the file type by its extension and tell if its contents match the extension.

You can also use a specific detector:

puts FileTypeDetector.pdf_check("path/to/your/real_pdf.pdf")    # true
puts FileTypeDetector.pdf_check("path/to/your/fake_pdf.pdf")    # false

puts FileTypeDetector.docx_check("path/to/your/real_docx.docx") # true
puts FileTypeDetector.docx_check("path/to/your/fake_docx.docx") # false

You can also run all the detectors on the file to determine its type using the identify method:

puts FileTypeDetector.identify("path/to/your/real_pdf.pdf")   # "pdf"
puts FileTypeDetector.identify("path/to/your/real_xml.pdf")   # "xml"
puts FileTypeDetector.identify("path/to/your/real_docx.docx") # docx
puts FileTypeDetector.identify("path/to/your/real_jpeg.png")  # jpeg
puts FileTypeDetector.identify("path/to/your/unknown.png")    # nil

Supported File Types

The gem provides support for detecting the following file types:

  • PDF
  • DOCX
  • PNG
  • GIF
  • JPEG/JPG
  • JSON
  • XML

You can contribute to the development of the gem by creating new detectors for other file types and improving existing code. Report bugs and submit feature requests through the GitHub repository.

You can visit our gem's page here - Rubygems.org

License

This gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 08 Apr 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