Joedb 10.2.1
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(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.pwrite(s.data(), s.size(), 0);
36 }
37 }
38 }
39 else if (command == "help") ///////////////////////////////////////////////
40 {
41 out << R"RRR(Blob Reader
42~~~~~~~~~~~
43 read_blob <blob> [<output_file_name>]
44
45)RRR";
46
47 return Status::ok;
48 }
49 else
50 return Status::not_found;
51
52 return Status::done;
53 }
54}
@ 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
JOEDB_FILE File
Definition File.h:25