- auto context = _session.session()->context();
- auto output_format = context->output_formats()["srzip"];
- auto device = _session.device();
- _output = output_format->create_output(device,
- {{"filename",
- Glib::Variant<Glib::ustring>::create(_file_name)}});
+ const auto context = session_.device_manager().context();
+ auto device = session_.device();
+
+ map<string, Glib::VariantBase> options = options_;
+
+ // If the output has the capability to write files, use it.
+ // Otherwise, open the output stream.
+ const auto opt_list = output_format_->options();
+ if (opt_list.find("filename") != opt_list.end())
+ options["filename"] =
+ Glib::Variant<Glib::ustring>::create(file_name_);
+ else
+ output_stream_.open(file_name_, ios_base::binary |
+ ios_base::trunc | ios_base::out);
+
+ output_ = output_format_->create_output(device, options);