{"id":16495441,"url":"https://github.com/andyld97/extensions","last_synced_at":"2025-10-30T09:47:55.854Z","repository":{"id":89233714,"uuid":"56803560","full_name":"andyld97/Extensions","owner":"andyld97","description":"Some useful code that you need from time to time","archived":false,"fork":false,"pushed_at":"2023-09-02T13:47:44.000Z","size":25,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-04T09:17:53.870Z","etag":null,"topics":["csharp","extension","extensions","file-extensions"],"latest_commit_sha":null,"homepage":"","language":"C#","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/andyld97.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2016-04-21T20:27:12.000Z","updated_at":"2022-03-12T20:48:00.000Z","dependencies_parsed_at":"2025-09-19T06:32:55.892Z","dependency_job_id":"b38eb123-08ff-479e-bb16-6995e5232230","html_url":"https://github.com/andyld97/Extensions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andyld97/Extensions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyld97%2FExtensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyld97%2FExtensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyld97%2FExtensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyld97%2FExtensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andyld97","download_url":"https://codeload.github.com/andyld97/Extensions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyld97%2FExtensions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281785975,"owners_count":26561249,"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-10-30T02:00:06.501Z","response_time":61,"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":["csharp","extension","extensions","file-extensions"],"created_at":"2024-10-11T14:29:39.553Z","updated_at":"2025-10-30T09:47:55.847Z","avatar_url":"https://github.com/andyld97.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C# Extensions\nSome useful code that you need from time to time\n\nByteUnit\n---\nNow available as a nuget package:   \n`dotnet add package ByteUnit --version 1.0.2`\n\n1. Calculate the length directly into the unit prefix which is appropriate:\n\n```cs\nvar value = ByteUnit.FindUnit(1024);\n// value.Length = Your new length\n// value.Type = Your new unit prefix.\n```\n\n2. Calculate e.g. 1024 KB to MB\n\n```cs\nvar value = ByteUnit.From(new ByteUnit(1024.0, Unit.KB), Unit.MB);\n// or alternative\nvar value = ByteUnit.From(ByteUnit.FromKB(1024), Unit.MB);\n```\n\n3. Compare two `ByteUnit`s\n```cs\nvar fileSize = ByteUnit.FromFileInfo(new System.IO.FileInfo(\"PATH\"));\n\nif (fileSize \u003c ByteUnit.FromMB(10))\n{\n    // e.g. only download this file if it's less than 10MB big.\n}\n```\n\n4. Easy conversation\n```cs\nvar value = ByteUnit.Parse(\"999.5 MB/s\");\nvar gb = value.To(Unit.GB);\n```\n\n5. Parse from string \n```cs\nvar value = ByteUnit.Parse(\"100 MB\");\n// var value = ByteUnit.Parse(\"999.5 MB/s\");\n// you can also use TryParse \n```\n\nByteUnit overrides the default `ToString()`-Method, so you can use it to format your values in strings. There is also an overload for \"bytes per seconds\", this will add `/s` to end of the formatted string!\n\nFileAssociation\n---\n\nUseful for associate a file extension with your program (with icon)\n\n```cs\n// Add\nFileAssociation.SetFileAssociation(\"_NAME_\", \"_EXTENSION_\", \"_PATH_TO_ICO\", \"_PATH_TO_EXE\"); \n\n// Delete\nFileAssociation.DeleteFileAssociation(\"_NAME_\", \"_EXTENSION_\");\n```\n\nZipHelper\n---\n```cs\n// Create a zip archive\nawait ZipHelper.CreateZipFileFromDirectoryAsync(@\"F:\\Data\", @\"C:\\Users\\test\\Desktop\\test.zip\");\n\n// Extract a zip archive\nawait ZipHelper.ExtractZipFileAsync(@\"C:\\Users\\test\\Desktop\\test.zip\", @\"F:\\Data\");\n```\n- You can also pass a `byte[]` to `ExtractZipFileAsync(...)`!\n- All methods are available synchronously (e.g. `ExtractZipFiles(...)`) and asynchronously (using `async` and `await`)!\n- If you are not using .NET Core there is no `System.IO.Path.GetRelative` Method. But you can use this [port](https://gist.github.com/antonKrouglov/07ccc117cb8c30ad8994446a86c062e5) instead!\n\nHash\n---\n```cs\n// Create hash from file\nstring hash = await Hash.CreateHashFromFileAsync(@\"F:\\Data\\test.iso\");\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandyld97%2Fextensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandyld97%2Fextensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandyld97%2Fextensions/lists"}