From 2b7d938315a7d5861ba9e876c99bbb70d8ec0003 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 10 Feb 2019 22:18:22 +0100 Subject: [PATCH] add base64 as format for read results --- README.md | 7 ++++--- example/www/js/filesystem.js | 4 ++-- lib/wsfs/operation/read.c | 5 +++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6c95940..c778559 100644 --- a/README.md +++ b/README.md @@ -258,9 +258,10 @@ Read from an open file. #### Format -| Format | Description | -| ---------- | ----------------------------------------------- | -| "identiy" | Use data as is; note that json is UTF-8 encoded | +| Format | Description | +| ---------- | -------------------------------------------------------- | +| "identiy" | Use data as is; note that JSON strings are UTF-8 encoded | +| "base64" | data is base64 encoded | # Build and run diff --git a/example/www/js/filesystem.js b/example/www/js/filesystem.js index f2ef6c0..034a8ff 100644 --- a/example/www/js/filesystem.js +++ b/example/www/js/filesystem.js @@ -117,8 +117,8 @@ class FileSystem { let end = Math.min(offset + length, entry.contents.length); let data = (offset < entry.contents.length) ? entry.contents.substring(offset, end) : ""; result = { - data: data, - format: "identity", + data: btoa(data), + format: "base64", count: data.length }; } diff --git a/lib/wsfs/operation/read.c b/lib/wsfs/operation/read.c index 0fbbd63..16c4e85 100644 --- a/lib/wsfs/operation/read.c +++ b/lib/wsfs/operation/read.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "wsfs/jsonrpc/server.h" @@ -25,6 +26,10 @@ static wsfs_status wsfs_fill_buffer( { memcpy(buffer, data, copy_count); } + else if (0 == strcmp("base64", format)) + { + lws_b64_decode_string(data, buffer, copy_count); + } else { status = WSFS_BAD;