{"id":20532656,"url":"https://github.com/cimpress-mcp/datauri","last_synced_at":"2026-05-30T22:32:14.109Z","repository":{"id":38061744,"uuid":"201999544","full_name":"Cimpress-MCP/DataUri","owner":"Cimpress-MCP","description":"Library to handle data uris","archived":false,"fork":false,"pushed_at":"2022-10-25T18:15:10.000Z","size":37,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2026-04-21T05:56:17.354Z","etag":null,"topics":["csharp","datauri"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Cimpress-MCP.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}},"created_at":"2019-08-12T19:55:56.000Z","updated_at":"2022-11-25T01:25:33.000Z","dependencies_parsed_at":"2023-01-19T15:03:31.073Z","dependency_job_id":null,"html_url":"https://github.com/Cimpress-MCP/DataUri","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Cimpress-MCP/DataUri","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cimpress-MCP%2FDataUri","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cimpress-MCP%2FDataUri/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cimpress-MCP%2FDataUri/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cimpress-MCP%2FDataUri/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cimpress-MCP","download_url":"https://codeload.github.com/Cimpress-MCP/DataUri/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cimpress-MCP%2FDataUri/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33712579,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-30T02:00:06.278Z","response_time":92,"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","datauri"],"created_at":"2024-11-16T00:16:20.948Z","updated_at":"2026-05-30T22:32:14.094Z","avatar_url":"https://github.com/Cimpress-MCP.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cimpress-MCP.DataUri\nA framework to handle converting objects to and from DataUris. With built in support for handling application/json DataUris. The framework is written in compliance with [RFC-2397](https://tools.ietf.org/html/rfc2397).\n\n# Using this library\n\n## Parsing DataUris\n\nThere is built-in support for handling dataUris with the media type of `application/json`.\n\n```cs\nclass Person\n{\n    public string Name { get; set; }\n}\n\nstring dataUri = \"data:application/json,{\\\"name\\\":\\\"andrew\\\"}\";\nPerson andrew = DataUri.ToObject\u003cPerson\u003e(dataUri);\nAssert.Equal(\"andrew\", andrew.Name);\n```\n\nAnother example with a base64 encoded payload\n\n```cs\nstring dataUri = \"data:application/json;base64,eyJuYW1lIjoiYW5kcmV3In0=\";\nPerson andrew = DataUri.ToObject\u003cPerson\u003e(dataUri);\nAssert.Equal(\"andrew\", andrew.Name);\n```\n\nAdditionally when dealing with large json payloadds the data of the uri can be compressed with the deflate or gzip algorithm.\n\n```cs\nstring dataUri = \"data:application/json;content-coding=deflate;base64,q1byS8xNVbJSSsxLKUotV6oFAA==\";\nPerson andrew = DataUri.ToObject\u003cPerson\u003e(dataUri);\nAssert.Equal(\"andrew\", andrew.Name);\n```\n\n### Handling other media types\n\nThe rules deserializing data uris is done by the media type of the dataUri. There is a registry of known media types the and interface to deserialize them. For example to add a deserializer for image/png using Bitmap and System.Drawing.\n\n```cs\nclass ImageDeserializer : IDataUriDeserializer\n{\n    public const string MEDIA_TYPE = \"image/png\";\n\n    public object DeserializeDataUri(DataUri dataUri, Type targetType)\n    {\n        byte[] imageBytes = dataUri.Base64 ? Convert.FromBase64String(dataUri.Data) : Encoding.UTF8.GetBytes(dataUri.Data);\n\n        using (MemoryStream memStream = new MemoryStream(imageBytes))\n        {\n            return new Bitmap(memStream);\n        }\n    }\n}\n\nDataUri.RegisterDataDeserializer(\"image/png\", new ImageDeserializer());\nstring dataUri = \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAWSURBVChTY6AdqP9/5T+UOQpIBQwMAB4hA1I5813pAAAAAElFTkSuQmCC\";\nBitmap image = DataUri.ToObject\u003cBitmap\u003e(dataUri);\n```\n\n## Creating a DataUri from an object\n\nBy default when dataUris are created from an object the object is serialized using Newtonsoft.Json, base64 encoded, and labeled as application/json.\n```cs\nPerson andrew = new Person()\n{\n    Name = \"andrew\"\n};\nvar dataUri = DataUri.FromObject(andrew);\ndataUri.ToString() =\u003e \"data:application/json;content-coding=deflate;base64,q1byS8xNVbJSSsxLKUotV6oFAA==\"\n```\n\n### Updating FromObject\n\nDifferent ObjectSerializationSettings can be provided to the FromObject method to change the behavoir. The most important part of the change is the `IObjectSerializer` that contains the rules for how to change an object into a byte array.\nFor example to use gzip as an encoding algorithm:\n\n```cs\nclass GZipSerializer : IObjectSerializer\n{\n    public Dictionary\u003cstring, string\u003e GetMediaTypeParameters()\n    {\n        return new Dictionary\u003cstring, string\u003e { { DataUri.CONTENT_ENCODING, GZip.GZIP } };\n    }\n\n    public byte[] Serialize(object obj)\n    {\n        string stringObj = JsonConvert.SerializeObject(obj);\n        return GZip.Encode(stringObj);\n    }\n}\nvar serializationSettings = new ObjectSerializationSettings(new GZipSerializer(), \"application/json\", true, null);\nPerson andrew = new Person()\n{\n    Name = \"andrew\"\n};\nDataUri dataUriGZip = DataUri.FromObject(andrew, serializationSettings);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcimpress-mcp%2Fdatauri","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcimpress-mcp%2Fdatauri","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcimpress-mcp%2Fdatauri/lists"}