{"action":"created","issue":{"url":"https://api.github.com/repos/sindresorhus/file-type/issues/39","labels_url":"https://api.github.com/repos/sindresorhus/file-type/issues/39/labels{/name}","comments_url":"https://api.github.com/repos/sindresorhus/file-type/issues/39/comments","events_url":"https://api.github.com/repos/sindresorhus/file-type/issues/39/events","html_url":"https://github.com/sindresorhus/file-type/issues/39","id":115255968,"number":39,"title":"Move magic patterns to JSON file","user":{"login":"matthewbauer","id":19036,"avatar_url":"https://avatars.githubusercontent.com/u/19036?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewbauer","html_url":"https://github.com/matthewbauer","followers_url":"https://api.github.com/users/matthewbauer/followers","following_url":"https://api.github.com/users/matthewbauer/following{/other_user}","gists_url":"https://api.github.com/users/matthewbauer/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewbauer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewbauer/subscriptions","organizations_url":"https://api.github.com/users/matthewbauer/orgs","repos_url":"https://api.github.com/users/matthewbauer/repos","events_url":"https://api.github.com/users/matthewbauer/events{/privacy}","received_events_url":"https://api.github.com/users/matthewbauer/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sindresorhus/file-type/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/sindresorhus/file-type/labels/help%20wanted","name":"help wanted","color":"159818"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-11-05T10:37:51Z","updated_at":"2015-11-09T00:05:13Z","closed_at":null,"body":"I'm thinking something like this:\r\n\r\n```json\r\n[\r\n\t{\r\n\t\t\"ext\": \"jpg\",\r\n\t\t\"mime\": \"image/jpeg\",\r\n\t\t\"patterns\": [\r\n\t\t\t{\r\n\t\t\t\t\"start\": 0,\r\n\t\t\t\t\"match\": \"FFD8FF\"\r\n\t\t\t}\r\n\t\t]\r\n\t},\r\n\t{\r\n\t\t\"ext\": \"png\",\r\n\t\t\"mime\": \"image/png\",\r\n\t\t\"patterns\": [\r\n\t\t\t{\r\n\t\t\t\t\"start\": 0,\r\n\t\t\t\t\"match\": \"89504E47\"\r\n\t\t\t}\r\n\t\t]\r\n\t},\r\n\t{\r\n\t\t\"ext\": \"gif\",\r\n\t\t\"mime\": \"image/gif\",\r\n\t\t\"patterns\": [\r\n\t\t\t{\r\n\t\t\t\t\"start\": 0,\r\n\t\t\t\t\"match\": \"474946\"\r\n\t\t\t}\r\n\t\t]\r\n\t}\r\n]\r\n```\r\n\r\nWould that be worthwhile? Just trying to get some input."},"comment":{"url":"https://api.github.com/repos/sindresorhus/file-type/issues/comments/154888250","html_url":"https://github.com/sindresorhus/file-type/issues/39#issuecomment-154888250","issue_url":"https://api.github.com/repos/sindresorhus/file-type/issues/39","id":154888250,"user":{"login":"alexanderlperez","id":3683232,"avatar_url":"https://avatars.githubusercontent.com/u/3683232?v=3","gravatar_id":"","url":"https://api.github.com/users/alexanderlperez","html_url":"https://github.com/alexanderlperez","followers_url":"https://api.github.com/users/alexanderlperez/followers","following_url":"https://api.github.com/users/alexanderlperez/following{/other_user}","gists_url":"https://api.github.com/users/alexanderlperez/gists{/gist_id}","starred_url":"https://api.github.com/users/alexanderlperez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexanderlperez/subscriptions","organizations_url":"https://api.github.com/users/alexanderlperez/orgs","repos_url":"https://api.github.com/users/alexanderlperez/repos","events_url":"https://api.github.com/users/alexanderlperez/events{/privacy}","received_events_url":"https://api.github.com/users/alexanderlperez/received_events","type":"User","site_admin":false},"created_at":"2015-11-09T00:05:13Z","updated_at":"2015-11-09T00:05:13Z","body":"The current way signatures are tested have an inherent logic to them (no pun intended), so anything that moves the complexity away from the the 'schema' of how the tests are structured seems like goldplating the architecture.  \r\n\r\nHowever, @thisconnect @matthewbauer, something that keeps to the simplicity of actual JS *would* be possible, maybe a reference JSON and a method to compare the stored signatures would be ideal, some thing like (ES5ish psuedocode 😅):\r\n\r\n``` \r\nvar ref = require('./reference.json');\r\n\r\nfunction testSignature(file, ref_entry) {\r\n... get the ref and any associated offset data and test against the file\r\n}\r\n\r\n// test the various mp4 container signatures saved in the JSON reference\r\nif (testSignature(file, ref.mp4_3gp) || testSignature(file, ref.mp4_isom) || testSignature(file, ref.mp4_etc) || ...) {\r\n return ...\r\n}\r\n\r\n// test the avi signature stored as multiple parts\r\nif (testSignature(file, ref.avi[0]) && testSignature(file, ref.avi[1])) {\r\n return ...\r\n}\r\n```\r\n\r\nAt a glance, most of the complexity would may stored in the JSON and how it's formatted. Moving past that and it's almost like defining a new configuration language, ie. building an interpreter.  \r\n\r\nThoughts?"}}