DF-0
DF-0: Data processing Framework with Zero-overhead
Loading...
Searching...
No Matches
content_type_by_file_extension.h
1/**************************************************************************/
2/* */
3/* DF-0: Data processing Framework with Zero-overhead */
4/* */
5/* Copyright (c) DF-0 Team https://github.com/df0-io/df0 */
6/* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-DF0-Commercial */
7/* */
8/**************************************************************************/
9
10#ifndef DF0_CONTENT_TYPE_BY_FILE_EXTENSION_H
11#define DF0_CONTENT_TYPE_BY_FILE_EXTENSION_H
12
13#include "pipeline/element_base.hpp"
14#include "content_type_export.h"
15#include "data_source.h"
16#include "document_elements.h"
17
22{
23
34DF0_CONTENT_TYPE_EXPORT void detect(data_source& data);
35
44DF0_CONTENT_TYPE_EXPORT std::optional<file_extension> to_extension(const mime_type& mt);
45
55class detector : public pipeline::transformer_element<detector>
56{
57public:
58 continuation operator()(message_ptr msg, const message_callbacks& emit_message)
59 {
60 if (msg->is<data_source>())
61 {
62 data_source& data = msg->get<data_source>();
63 detect(data);
64 }
65 else if (msg->is<document::image>())
66 {
67 data_source& data = msg->get<document::image>().source;
68 detect(data);
69 }
70 return emit_message(std::move(msg));
71 }
72};
73
74} // namespace df0::content_type::by_file_extension
75
76#endif // DF0_CONTENT_TYPE_BY_FILE_EXTENSION_H
DF0_CONTENT_TYPE_EXPORT void detect(data_source &data)
Detects and assigns content types to the provided data source using file extension.
DF0_CONTENT_TYPE_EXPORT std::optional< file_extension > to_extension(const mime_type &mt)
Converts a mime type to a file extension.
Callback bundle used by pipeline elements to emit messages.
Definition message.h:90
Wrapper for a MIME type string.
Definition data_source.h:59