{"id":13307277,"url":"https://github.com/maitag/whatformat","last_synced_at":"2025-03-10T14:32:50.966Z","repository":{"id":85337336,"uuid":"117389820","full_name":"maitag/whatformat","owner":"maitag","description":"little haxe library that detects various formats by parsing header or filename","archived":false,"fork":false,"pushed_at":"2020-05-23T00:35:42.000Z","size":17,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-02-26T06:46:12.516Z","etag":null,"topics":["fileformat","fileheader","haxe","magic-numbers"],"latest_commit_sha":null,"homepage":"","language":"Haxe","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maitag.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-14T00:34:57.000Z","updated_at":"2021-05-16T19:44:14.000Z","dependencies_parsed_at":"2023-04-13T12:37:37.908Z","dependency_job_id":null,"html_url":"https://github.com/maitag/whatformat","commit_stats":null,"previous_names":[],"tags_count":1,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maitag%2Fwhatformat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maitag%2Fwhatformat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maitag%2Fwhatformat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maitag%2Fwhatformat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maitag","download_url":"https://codeload.github.com/maitag/whatformat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242868650,"owners_count":20198525,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fileformat","fileheader","haxe","magic-numbers"],"created_at":"2024-07-29T18:00:15.861Z","updated_at":"2025-03-10T14:32:50.956Z","avatar_url":"https://github.com/maitag.png","language":"Haxe","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WhatFormat\npure [haxe](https://haxe.org)-library to detect fileformat by [Magick Numbers](https://en.wikipedia.org/wiki/Magic_number_(programming)) or by filename.  \n\n\n## Installation\n\n```\nhaxelib install whatformat\n```\n\nor use the latest developement version from github:  \n```\nhaxelib git whatformat https://github.com/maitag/whatformat.git\n```\n\n\n\n## Documentation\n\nStart with an instance of __WhatFormat__:\n\n```\nvar wtf = new WhatFormat();\n\n// or define what formats to check only:\n// var wtf = new WhatFormat(['png', 'jpg', 'gif']); \n```\n\n\n\n\nTo check the __Bytes__ in the __header__ of a loaded File:\n\n```\nvar bytes:Bytes = File.getBytes(filename);\nif ( wtf.checkHeaderBytes(bytes).found ) trace('format: ${wtf.format} - ${wtf.description}');\n\n```\n\n\n\n\nFor __streams__ or special purpose you can check format __while loading__,  \nto easy __stop__ loading if no fileformat can be detected by header:\n\n```\nvar file:FileInput = File.read(filename);\nvar wtf:WhatFormat = new WhatFormat();\ntry {\n\tdo {\n\t\tvar byte:Int = file.readByte();\n\t\t// ... store it into Bytes or do whatever with\n\t\t\n\t\twtf.checkNextByte(byte); // check next Byte in header (if formatcheck is in proceed)\n\t}\n\twhile ( wtf.proceed || wtf.found); // stop reading if no format found\n}\ncatch( ex:haxe.io.Eof ) {}\n\nif (wtf.found) trace( 'format: ${wtf.format} - ${wtf.description}');\nelse trace(\"can't detect fileformat\");\n\nfile.close();\n```\n\n\n\n\nYou can also check the __ending__ of a __filename__:\n\n```\nif (wtf.checkFilenameEnding(filename).found) {\n\ttrace('format detected by filename ending:\\n');\n\ttrace('format: ${wtf.format} - ${wtf.description}');\n\ttrace('subtype: ${wtf.format} - ${wtf.subtypeDescription}');\n}\n```\n\n\n\nor __combine__ both methods:\n\n```\nvar wtf:WhatFormat = new WhatFormat();\n\n// detect by filename\nif (wtf.checkFilenameEnding(filename).found)\n\ttrace('format detected by filename ending:\\n', wtf.byName);\n\nvar input:Bytes;\nvar cache:BytesOutput = new BytesOutput();\nvar file:FileInput = File.read(filename);\nvar byte:Int;\ntry {\n\tdo {\n\t\tbyte = file.readByte();\n\t\tcache.writeByte(byte);\n\t}\n\twhile ( wtf.checkNextByte(byte) || wtf.found); // do not stop if something found byName or byHeader\n}\ncatch( ex:haxe.io.Eof ) {}\nfile.close();\n\n// detected by header\nif (wtf.byHeader.found) trace('format detected by parsing header:\\n', wtf.byHeader);\n\n// check again what filename-detection found\n// if (wtf.byName.found) trace('format detected by filename - subtype:\\n', wtf.byName.subtype);\n\n// detected by byHeader OR byName\nif (wtf.found) {\n\tinput = cache.getBytes();\n\ttrace('format of $filename found.');\n\ttrace('filesize: ${input.length}');\n\n\t// if you not prefer the \"header-first\" autoselection method here,\n\t// set the second parameter in instantiation to false: wtf = new WhatFormat(null, false);\n\ttrace('format: ${wtf.format} - ${wtf.description}');\n\tif (wtf.subtype != null) trace('subtype:${wtf.subtype} - ${wtf.subtypeDescription}');\n}\nelse trace(\"can't detect fileformat\");\n```\n\nFor __another check__ with the __same instance__ of `wtf`,  \nin some cases you need to reset the detected results to defaults:\n```\nwtf.byHeader.reset();// resets wtf.byHeader values and get ready for another 'wtf.checkNextByte()'\nwtf.byName.reset(); // resets wtf.byName values\nwtf.reset();       // resets both\n```\n\n\n\n## Supported Formats\n\nLook here: [src/formats/Magic.hx](https://github.com/maitag/whatformat/blob/master/src/formats/Magic.hx) \nor test out [Drag \u0026 Drop Sample](https://github.com/maitag/dragdrop) in your Webbrowser [--\u003e here](http://maitag.de/semmi/haxelime/dragdrop).  \n  \nFeel free to __commit__ new formats that needs a `wtf-check`;)  \n\n\n## Todo\n\n- add more formats\n- check subtypes headers (container-formats, streams)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaitag%2Fwhatformat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaitag%2Fwhatformat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaitag%2Fwhatformat/lists"}