View Source Infer.Text (Infer v0.2.4)

Text type matchers based on the magic number

Link to this section Summary

Functions

Takes the binary file contents as arguments. Returns true if it's html.

Takes the binary file contents as arguments. Returns true if it's a shell script.

Takes the binary file contents as arguments. Returns true if it's xml.

Link to this section Functions

Specs

html?(binary()) :: boolean()

Takes the binary file contents as arguments. Returns true if it's html.

See: https://mimesniff.spec.whatwg.org/

examples

Examples

iex> Infer.Text.html?("<!DOCTYPE html>")
true

iex> Infer.Text.html?("     <BODY>")
true

iex> Infer.Text.html?("<")
false

iex> binary = File.read!("test/archives/sample.zip")
iex> Infer.Text.html?(binary)
false

Specs

shell_script?(binary()) :: boolean()

Takes the binary file contents as arguments. Returns true if it's a shell script.

examples

Examples

iex> Infer.Text.shell_script?("#!/bin/sh") true

iex> binary = File.read!("test/archives/sample.zip") iex> Infer.Text.shell_script?(binary) false

Specs

xml?(binary()) :: boolean()

Takes the binary file contents as arguments. Returns true if it's xml.

See: https://mimesniff.spec.whatwg.org/

examples

Examples

iex> Infer.Text.xml?(~s(<?xml version="1.0" encoding="ISO-8859-1"?>))
true

iex> binary = File.read!("test/archives/sample.zip")
iex> Infer.Text.xml?(binary)
false