{"id":25714022,"url":"https://github.com/vicajilau/file_magic_number","last_synced_at":"2025-08-20T05:16:14.387Z","repository":{"id":277713558,"uuid":"933281102","full_name":"vicajilau/file_magic_number","owner":"vicajilau","description":"A Flutter package to detect file types based on their magic number instead of MIME types. Supports Flutter on mobile, desktop, and web without native code.","archived":false,"fork":false,"pushed_at":"2025-08-18T16:45:14.000Z","size":830,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-18T18:31:36.470Z","etag":null,"topics":["binary-file","dart","file-type-detection","flutter","flutter-package","magic-number","magic-numbers"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/file_magic_number","language":"Dart","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/vicajilau.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2025-02-15T15:33:27.000Z","updated_at":"2025-08-18T16:45:11.000Z","dependencies_parsed_at":"2025-03-23T08:18:40.748Z","dependency_job_id":"80d1d964-ace5-4a8e-a0f8-3449e82a51c5","html_url":"https://github.com/vicajilau/file_magic_number","commit_stats":null,"previous_names":["vicajilau/file_magic_number"],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/vicajilau/file_magic_number","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicajilau%2Ffile_magic_number","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicajilau%2Ffile_magic_number/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicajilau%2Ffile_magic_number/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicajilau%2Ffile_magic_number/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vicajilau","download_url":"https://codeload.github.com/vicajilau/file_magic_number/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicajilau%2Ffile_magic_number/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271043468,"owners_count":24689765,"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","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["binary-file","dart","file-type-detection","flutter","flutter-package","magic-number","magic-numbers"],"created_at":"2025-02-25T12:27:51.747Z","updated_at":"2025-08-20T05:16:14.364Z","avatar_url":"https://github.com/vicajilau.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://pub.dev/packages/file_magic_number\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/vicajilau/file_magic_number/main/.github/assets/file_magic_number.png\" height=\"200\" alt=\"File Magic Number Logo\"\u003e\n  \u003c/a\u003e\n  \u003ch1 align=\"center\"\u003eFile Magic Number\u003c/h1\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://pub.dev/packages/file_magic_number\"\u003e\n    \u003cimg src=\"https://img.shields.io/pub/v/file_magic_number?label=pub.dev\u0026labelColor=333940\u0026logo=dart\" alt=\"Pub Version\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/vicajilau/file_magic_number/actions/workflows/dart_analyze_unit_test.yml\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/vicajilau/file_magic_number/dart_analyze_unit_test.yml?branch=main\u0026label=CI\u0026labelColor=333940\u0026logo=github\" alt=\"CI Status\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/vicajilau/pdf_combiner/actions/workflows/publish_pub_dev.yml\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/vicajilau/file_magic_number/publish_pub_dev.yml?label=CD\u0026labelColor=333940\u0026logo=github\" alt=\"CD Status\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/vicajilau/file_magic_number\"\u003e\n    \u003cimg src=\"https://img.shields.io/codecov/c/github/vicajilau/file_magic_number?logo=codecov\u0026logoColor=fff\u0026labelColor=333940\" alt=\"Code Coverage\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\nA Flutter package to detect file types based on their magic number instead of relying on MIME types. Works on Flutter for mobile, desktop, and web without requiring native code.\n\n## 🚀 Features\n- Detects file types using their magic number (signature bytes)\n- Get bytes `Uint8List` from path or blob. \n- Supports Flutter on Android, iOS, macOS, Windows, Linux, and Web\n- No need for native plugins\n- Lightweight and easy to extend with custom signatures\n\n## 📌 Installation\nAdd the dependency to your `pubspec.yaml`:\n\n```yaml\ndependencies:\n  file_magic_number: latest_version\n```\n\nThen for Flutter, run:\n```sh\nflutter pub get\n```\n\n## 🛠️ Usage\n\n### Detect a file type from bytes\nWe can synchronously detect the file type using the bytes of the file.\n```dart\nimport 'package:file_magic_number/file_magic_number.dart';\n\nvoid main() {\n  final bytes = Uint8List.fromList([0x25, 0x50, 0x44, 0x46]);\n  final FileMagicNumberType fileType = FileMagicNumber.detectFileTypeFromBytes(bytes);\n  print(fileType);\n}\n```\n\n### Detect a file type from path or blob\nWe can asynchronously detect the file type using the path or blob of the file.  \nThis requires that for Android, iOS, Linux, MacOS, and Windows, we pass the file path.  \nIn the web version, this parameter must be the blob of the file.\n\n\u003e **Note:** This method may throw a `PathNotFoundException` if the file is not found.  \n\u003e It is recommended to handle this exception appropriately as shown in the following example.\n\n```dart\nimport 'package:file_magic_number/file_magic_number.dart';\n\nvoid main() async {\n  final pathOrBlob = \"my_path_or_blob\";\n  try {\n    final FileMagicNumberType fileType = await FileMagicNumber.detectFileTypeFromPathOrBlob(pathOrBlob);\n    print(fileType);\n  } catch (e) {\n    print(\"The file was not found.\");\n  }\n}\n```\n\n### Get Uint8List from path or blob\nWe can asynchronously get the bytes of the file using the path or blob of the file.  \nThis requires that for Android, iOS, Linux, MacOS, and Windows, we pass the file path.  \nIn the web version, this parameter must be the blob of the file.\n\n\u003e **Note:** This method may throw a `PathNotFoundException` if the file is not found.  \n\u003e It is recommended to handle this exception appropriately as shown in the following example.\n\n```dart\nimport 'package:file_magic_number/file_magic_number.dart';\n\nvoid main() async {\n  final pathOrBlob = \"my_path_or_blob\";\n  try {\n    final Uint8List bytes = await FileMagicNumber.getBytesFromPathOrBlob(pathOrBlob);\n    print(bytes);\n  } catch (e) {\n    print(\"The file was not found.\");\n  }\n}\n```\n\n### Detect a file type from file_picker\nIntegrating file_magic_number with [file_picker](https://pub.dev/packages/file_picker) allows you to easily detect the type of a file selected by the user without relying on MIME types.\n\n#### Using bytes\nYou can use file_picker to open the file dialog and then pass the file's bytes to [FileMagicNumber.detectFileTypeFromBytes](https://github.com/vicajilau/file_magic_number/blob/main/lib/file_magic_number_type.dart) to identify its type.\nHere's how you can do it:\n```dart\nimport 'package:file_magic_number/file_magic_number.dart';\nimport 'package:file_picker/file_picker.dart';\n\nvoid main() async {\n  FilePickerResult? result = await FilePicker.platform.pickFiles(withData: true);\n\n  if (result != null) {\n    final FileMagicNumberType fileType = FileMagicNumber.detectFileTypeFromBytes(result.files.single.bytes);\n    print(fileType);\n  }\n}\n```\n\n#### Using pathOrBlob\nYou can use file_picker to open the file dialog and then pass the file's path or blob to [FileMagicNumber.detectFileTypeFromBytes](https://github.com/vicajilau/file_magic_number/blob/main/lib/file_magic_number_type.dart) to identify its type.\nHere's how you can do it:\n\n\u003e **Note:** This method may throw a `PathNotFoundException` if the file is not found.  \n\u003e It is recommended to handle this exception appropriately as shown in the following example.\n\n```dart\nimport 'package:file_magic_number/file_magic_number.dart';\nimport 'package:file_picker/file_picker.dart';\n\nvoid main() async {\n  FilePickerResult? result = await FilePicker.platform.pickFiles();\n\n  if (result != null \u0026\u0026 result.files.single.path != null) {\n    try {\n      final FileMagicNumberType fileType = await FileMagicNumber.detectFileTypeFromPathOrBlob(result.files.single.path!);\n      print(fileType);\n    } catch (e) {\n      print(\"The file was not found.\");\n    }\n  }\n}\n```\n\n## 🎯 Supported File Types\n| File Type | Magic Number (Hex)        |\n|-----------|---------------------------|\n| ZIP       | 50 4B 03 04               |\n| RAR       | 52 61 72 21 1A 07 00      |\n| RAR       | 52 61 72 21 1A 07         |\n| 7Z        | 37 7A BC AF 27 1C         |\n| PDF       | 25 50 44 46               |\n| PNG       | 89 50 4E 47 0D 0A 1A 0A   |\n| JPG       | FF D8 FF                  |\n| GIF       | 47 49 46 38               |\n| HEIC      | 66 74 79 70 68 65 69 63   |\n| TIFF      | 49 49 2A 00 / 4D 4D 00 2A |\n| BMP       | 42 4D                     |\n| MP3       | 49 44 33                  |\n| WAV       | 52 49 46 46               |\n| MP4       | 66 74 79 70               |\n| ELF       | 7F 45 4C 46               |\n| EXE       | 4D 5A                     |\n| TAR       | 75 73 74 61 72            |\n| SQLite    | 53 51 4C 69 74 65         |\n\n## 📌 Contributing\nFeel free to contribute by adding more file signatures or improving the implementation. Fork the repo and submit a PR!\n\n## 📜 License\nThis project is licensed under the MIT License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicajilau%2Ffile_magic_number","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvicajilau%2Ffile_magic_number","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicajilau%2Ffile_magic_number/lists"}