{"id":16640030,"url":"https://github.com/hueifeng/tinyvfs","last_synced_at":"2025-03-16T22:31:24.452Z","repository":{"id":37041430,"uuid":"266465354","full_name":"hueifeng/TinyVFS","owner":"hueifeng","description":" The virtual file system embeds (js, css, html, cshtml) and other files into the dll, so that it can be used like a physical file during operation.","archived":false,"fork":false,"pushed_at":"2024-08-18T12:45:03.000Z","size":826,"stargazers_count":24,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-13T07:07:52.601Z","etag":null,"topics":["assembly","cshtml","embedded","embedded-files","middleware","netcore","physical-files","razor","virtual-files"],"latest_commit_sha":null,"homepage":"","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/hueifeng.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":"2020-05-24T03:52:22.000Z","updated_at":"2024-08-18T12:45:06.000Z","dependencies_parsed_at":"2023-02-09T20:01:11.303Z","dependency_job_id":null,"html_url":"https://github.com/hueifeng/TinyVFS","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hueifeng%2FTinyVFS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hueifeng%2FTinyVFS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hueifeng%2FTinyVFS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hueifeng%2FTinyVFS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hueifeng","download_url":"https://codeload.github.com/hueifeng/TinyVFS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221668568,"owners_count":16860677,"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":["assembly","cshtml","embedded","embedded-files","middleware","netcore","physical-files","razor","virtual-files"],"created_at":"2024-10-12T07:07:40.536Z","updated_at":"2024-10-27T11:28:05.660Z","avatar_url":"https://github.com/hueifeng.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TinyVFS \n\n[![nuget](https://img.shields.io/nuget/v/TinyVFS.svg?style=flat-square)](https://www.nuget.org/packages/TinyVFS) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fhueifeng%2FTinyVFS.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fhueifeng%2FTinyVFS?ref=badge_shield)\n![.NET Core](https://github.com/hueifeng/TinyVFS/workflows/.NET%20Core/badge.svg)\n[![stats](https://img.shields.io/nuget/dt/TinyVFS.svg?style=flat-square)](https://www.nuget.org/stats/packages/TinyVFS?groupby=Version) [![GitHub license](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/hueifeng/TinyVFS/master/LICENSE)\n\nLanguage: English | [中文](README.zh-cn.md)\n\n`TinyVFS` is a virtual file system, inspired by the ABP vNext framework. It can embed js, css, image, cshtml and other files into the assembly,\nAnd they can be used like physical files at runtime.\n\n#### Features\n\n* In a single application, it can divide the front end and back end (management system) into separate project projects.\n* In development it allows developers to develop different businesses or modules at the same time.\n* It allows us to split the system function modules and assemble them together.\n\n## Quick Start\n\n1、Install Package\n\n```powershell\nInstall-Package TinyVFS\n```\n\n2、Registering Embedded Files\n\nEdit web resource project `.csproj`\n```csharp\n\u003cItemGroup\u003e\n  \u003cEmbeddedResource Include=\"MyResources\\**\\*.*\" /\u003e\n  \u003cContent Remove=\"MyResources\\**\\*.*\" /\u003e\n\u003c/ItemGroup\u003e\n```\n\nEmbed the file into the virtual file system with the following code snippet.\n\n```csharp\nservices.AddVirtualFilesService();\n     services.Configure\u003cVirtualFileSystemOptions\u003e(options =\u003e\n     {\n          options.FileSets.AddEmbedded\u003cWebApplication1.Pages.IndexModel\u003e(\"WebResources\");\n     });\n```\n\n\n\n3、Getting Virtual Files: IVirtualFileProvider\n\nAfter embedding into the assembly, you can obtain the file or directory content through `IVirtualFileProvider`\n\n```csharp\npublic class MyService\n{\n    private readonly IVirtualFileProvider _virtualFileProvider;\n\n    public MyService(IVirtualFileProvider virtualFileProvider)\n    {\n        _virtualFileProvider = virtualFileProvider;\n    }\n\n    public void Foo()\n    {\n        //Getting a single file\n        var file = _virtualFileProvider.GetFileInfo(\"/MyResources/js/test.js\");\n        var fileContent = file.ReadAsString(); //ReadAsString is an extension method of ABP\n\n        //Getting all files/directories under a directory\n        var directoryContents = _virtualFileProvider.GetDirectoryContents(\"/MyResources/js\");\n    }\n}\n```\n\n4、Dynamic listening file\n\nWhen we are developing on the local machine, maybe we will modify the static files in the resource project, so the normal operation can let us regenerate the code\n\nNow we can use `ReplaceEmbeddedByPhysical` to refresh through the browser to get the latest file information\n\n```csharp\nservices.AddVirtualFilesService();\n          services.Configure\u003cVirtualFileSystemOptions\u003e(options =\u003e\n          {\n              options.FileSets.ReplaceEmbeddedByPhysical\u003cWebApplication1.Pages.IndexModel\u003e(\n               Path.Combine(WebHostEnvironment.ContentRootPath, \"..\\\\WebResources\")\n           );\n          });\n\n```\n\n5、Virtual Files Middleware\n\n\nVirtual file middleware is used to provide embedded (js, css, image ...) files to the client/browser,\nJust like the physical (static) file in the wwwroot folder. Add it after the static file middleware, as shown below:\n\n```csharp\napp.UseVirtualFiles();\n```\n\nIf you want to extend other file formats, you can use the overloaded method, as shown below:\n\n```csharp\nvar provider = new FileExtensionContentTypeProvider();\nprovider.Mappings[\".less\"] = \"text/css\";\napp.UseVirtualFiles(provider);\n```\n\n\nBy setting the virtual file middleware, it is possible to place the physical file in the same position of the virtual file, thereby making it possible for the physical file to cover the virtual file.\n\n6、ASP.NET Core Integration\n\n\nVirtual files can be integrated directly into ASP.NET Core\n\n\n-  Virtual files can be used like physical static files in web applications.\n-  Razor Views, Razor Pages, js, css, image files and all other web content can be embedded in the assembly and used like physical files.\n-  The application can overwrite the virtual file of the module (web resource), just like putting a file with the same name and extension into the same folder of the virtual file.\n\n7、Views \u0026 Pages\n\n\nThey do not require any configuration and can be used in our applications. When these files exist in our physical directory, they overwrite the virtual files.\n\n## Next Steps\n\nClick the button below to start a new development environment:\n\n[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/hueifeng/TinyVFS)\n\n## Contribution\n\nIf you have any ideas you can join in, or find that there is code in this project that needs improvement, welcome to Fork and submit a PR!\n\n## License\n\n[Apache](https://raw.githubusercontent.com/hueifeng/TinyVFS/master/LICENSE)\n\n## Reference\n\n- [ABP vNext](https://github.com/abpframework/abp)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhueifeng%2Ftinyvfs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhueifeng%2Ftinyvfs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhueifeng%2Ftinyvfs/lists"}