This example shows how to perform file type detection (with or without document processing) by file extension or file signature or rely on provided mime-type
#include "docwire.h"
#include <fstream>
int main()
{
std::stringstream out_stream;
const std::string expected_output_1 = "Data processing refers to the activities performed on raw data to convert it into meaningful information. It involves collecting, organizing, analyzing, and interpreting data to extract useful insights and support decision-making. This can include tasks such as sorting, filtering, summarizing, and transforming data through various computational and statistical methods. Data processing is essential in various fields, including business, science, and technology, as it enables organizations to derive valuable knowledge from large datasets, make informed decisions, and improve overall efficiency.\n\n";
const std::string expected_output_2 = "<http://www.silvercoders.com/>hyperlink test\n\n";
try
{
std::make_shared<std::ifstream>("data_processing_definition.doc", std::ios::binary)
}};
ensure(mt.has_value()) ==
true;
{
seekable_stream_ptr{std::make_shared<std::ifstream>(
"data_processing_definition.doc", std::ios::binary)},
confidence::high
} |
ensure(out_stream.str()) == expected_output_1;
out_stream.str("");
{
seekable_stream_ptr{std::make_shared<std::ifstream>(
"data_processing_definition.doc", std::ios::binary)},
} |
ensure(out_stream.str()) == expected_output_1;
out_stream.str("");
std::filesystem::path{"data_processing_definition.doc"} |
ensure(out_stream.str()) == expected_output_1;
out_stream.str("");
std::make_shared<std::ifstream>("test.zip", std::ios::binary)
}};
ensure(zip_data_mt.has_value()) ==
true;
std::filesystem::path{"test.zip"} |
{
return emit_message(std::move(msg));
if (!mt || *mt !=
mime_type {
"application/msword" })
return continuation::skip;
return emit_message(std::move(msg));
} |
ensure(out_stream.str()) == expected_output_2;
out_stream.str("");
std::filesystem::path{"test.zip"} |
ensure(out_stream.str()) == expected_output_2;
}
catch (const std::exception& e)
{
return 1;
}
return 0;
}
Content type detection chain element.
std::optional< mime_type > highest_confidence_mime_type() const
Returns the MIME type with the highest confidence.
A utility for creating expressive, exception-throwing assertions in a fluent style.
A class representing a file extension.
Exports data to plain text format.
DOCWIRE_CONTENT_TYPE_EXPORT void detect(data_source &data, const by_signature::database &signatures_db_to_use=by_signature::database{})
std::string diagnostic_message(const std::exception &e)
Generates a diagnostic message for the given nested exceptions chain.
The main namespace for the DocWire SDK.
Wrapper for a MIME type string.
Wrapper for a shared pointer to a seekable input stream.