MCPcopy Create free account
hub / github.com/lief-project/LIEF / into_stream

Method into_stream

api/python/src/typing/InputParser.cpp:27–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25
26namespace LIEF::py::typing {
27std::unique_ptr<BinaryStream> InputParser::into_stream() {
28 if (auto path_str = path_to_str(*this)) {
29 if (auto strm = VectorStream::from_file(*path_str)) {
30 return std::make_unique<VectorStream>(std::move(*strm));
31 }
32 return nullptr;
33 }
34
35 if (nb::isinstance<nb::bytes>(*this)) {
36 auto bytes = nb::cast<nb::bytes>(*this);
37 return std::make_unique<SpanStream>(
38 static_cast<const uint8_t*>(bytes.data()), bytes.size()
39 );
40 }
41
42 if (nb::isinstance<nb::list>(*this)) {
43 auto bytes = nb::cast<std::vector<uint8_t>>(*this);
44 return std::make_unique<VectorStream>(std::move(bytes));
45 }
46
47 if (auto stream = PyIOStream::from_python(*this)) {
48 return std::make_unique<PyIOStream>(std::move(*stream));
49 }
50
51 logging::log(logging::LEVEL::ERR,
52 "LIEF parser interface does not support this Python object: " +
53 type2str(*this));
54 return nullptr;
55}
56}

Callers 5

create<Parser>Function · 0.80
create<Parser>Function · 0.80
create<Parser>Function · 0.80
create<Parser>Function · 0.80
create<Parser>Function · 0.80

Calls 6

path_to_strFunction · 0.85
type2strFunction · 0.85
from_pythonFunction · 0.50
logFunction · 0.50
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected