diff --git a/docs/README.md b/docs/README.md index bba22335..1b46bffd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3531,36 +3531,37 @@ mg_http_serve_dir(c, hm, &opts); ### Packed filesystem -Packed filesystem allow to "pack" filesystem into single file, for example, into -executable or flashable image. This is useful, for example, for implementation of HTTP-server on devices without filesystem. +Mongoose +has a filesystem abstraction layer. By default, a POSIX filesystem, +a FatFS filesystem, and a "packed" filesystem are implemented. + +A packed filesystem allow to "pack" filesystem into single file, for example, +into executable or flashable image - and files will be hardcoded into the +binary, making it possible to e.g. serve files on devices with no +filesystem, or be resilient to filesystem issues: + +packed filesystem In order to use packed filesystem do the following: -1. Compile file test\pack.c: - ```sh - $ cc -o pack pack.c - ``` - -2. Convert list of files into single .c: - ```sh - $ ./pack file1.data file2.data > fs.c - ``` - -3. Build your app with fs.c: - ```sh - $ cc -o my_app my_app.c fs.c - ``` - -4. In your application code, you can access files using this function:
- `const char *mg_unpack(const char *file_name, size_t *size)` or app can also - force `mg_http_serve_dir` function to use packed file system: - -```c -struct mg_http_serve_opts opts; -opts.fs = &mg_fs_packed; // Set packed ds as a file system -mg_http_serve_dir(c, hm, &opts); +```sh +$ cc -o pack pack.c # The pack.c file is test/ repo directory ``` - +2. Convert list of files into single .c: +```sh +$ ./pack index.html style.css > packed_fs.c +``` + +3. Build your app with `packed_fs.c`: +```sh +$ cc mongoose.c app.c packed_fs.c -DMG_ENABLE_PACKED_FS=1 +``` + +4. In your application code: +```c +struct mg_http_serve_opts opts = {}; // Initialise empty options +opts.fs = &mg_fs_packed; // Use packed filesystem +mg_http_serve_dir(c, hm, &opts); // Serve directory +``` - diff --git a/docs/images/packed.png b/docs/images/packed.png deleted file mode 100644 index a2ae271f..00000000 Binary files a/docs/images/packed.png and /dev/null differ diff --git a/docs/images/packed.svg b/docs/images/packed.svg new file mode 100644 index 00000000..12ab3ab1 --- /dev/null +++ b/docs/images/packed.svg @@ -0,0 +1 @@ +PACKBUILDAppfilex.ymain.jsstyle.cssintex.htmlintex.htmlmain.jspacked_fc.cmg-unpack() - get file datamg-unlist() - get file list \ No newline at end of file