Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Blob_Reader_Command_Processor.cpp
Go to the documentation of this file.
2#include "joedb/ui/type_io.h"
4#include "joedb/Blob.h"
5
6namespace joedb
7{
8 ////////////////////////////////////////////////////////////////////////////
9 Command_Processor::Status Blob_Reader_Command_Processor::process_command
10 ////////////////////////////////////////////////////////////////////////////
11 (
12 const std::string &command,
13 std::istream &parameters,
14 std::istream &in,
15 std::ostream &out
16 )
17 {
18 if (command == "read_blob") ///////////////////////////
19 {
20 const Blob blob = read_blob(parameters);
21
22 if (!blob.is_null())
23 {
24 const std::string s = blob_reader.read_blob_data(blob);
25 const std::string file_name = read_string(parameters);
26
27 if (file_name.empty())
28 {
29 write_string(out, s);
30 out << '\n';
31 }
32 else
33 {
34 File file(file_name, joedb::Open_Mode::create_new);
35 file.write_data(s.data(), s.size());
36 file.flush();
37 }
38 }
39 }
40 else if (command == "help") ///////////////////////////////////////////////
41 {
42 out << R"RRR(Blob Reader
43~~~~~~~~~~~
44 read_blob <blob> [<output_file_name>]
45
46)RRR";
47
48 return Status::ok;
49 }
50 else
51 return Status::not_found;
52
53 return Status::done;
54 }
55}
@ create_new
fails if already exists, locks the file for writing
void write_string(std::ostream &out, const std::string &s, bool json)
std::string read_string(std::istream &in)
Definition type_io.cpp:12
Blob read_blob(std::istream &in)
Definition type_io.cpp:250
Definition Blob.h:7
JOEDB_FILE File
Definition File.h:25