diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-05-04 22:28:12 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-05-07 01:14:52 +0200 |
commit | 0500d4347a6d31ef05fd860559e380c2e488c194 (patch) | |
tree | 26a22f65b7400d7fd26df5720fe2bbabd7b6de09 /libqpdf/JSON.cc | |
parent | 05fda4afa289ef248804865d7648c9ac3ae75fbd (diff) | |
download | qpdf-0500d4347a6d31ef05fd860559e380c2e488c194.tar.zst |
JSON: add blob type that generates base64-encoded binary data
Diffstat (limited to 'libqpdf/JSON.cc')
-rw-r--r-- | libqpdf/JSON.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc index 71ea33d7..8549b7ed 100644 --- a/libqpdf/JSON.cc +++ b/libqpdf/JSON.cc @@ -1,6 +1,8 @@ #include <qpdf/JSON.hh> #include <qpdf/BufferInputSource.hh> +#include <qpdf/Pl_Base64.hh> +#include <qpdf/Pl_Concatenate.hh> #include <qpdf/Pl_String.hh> #include <qpdf/QTC.hh> #include <qpdf/QUtil.hh> @@ -168,6 +170,22 @@ JSON::JSON_null::write(Pipeline* p, size_t) const *p << "null"; } +JSON::JSON_blob::JSON_blob(std::function<void(Pipeline*)> fn) : + fn(fn) +{ +} + +void +JSON::JSON_blob::write(Pipeline* p, size_t) const +{ + *p << "\""; + Pl_Concatenate cat("blob concatenate", p); + Pl_Base64 base64("blob base64", &cat, Pl_Base64::a_encode); + fn(&base64); + base64.finish(); + *p << "\""; +} + void JSON::write(Pipeline* p, size_t depth) const { @@ -306,6 +324,12 @@ JSON::makeNull() return JSON(std::make_shared<JSON_null>()); } +JSON +JSON::makeBlob(std::function<void(Pipeline*)> fn) +{ + return JSON(std::make_shared<JSON_blob>(fn)); +} + bool JSON::isArray() const { |