bencode
bencode copied to clipboard
Allow decoding from a file handle
This changes the decoder to read from an interface (Rych\Bencode\DataSource
) instead of directly from a string. String
and FileHandle
DataSource implementations are built in. A file can be decoded given a file handle:
$file = fopen('path/to/file.bin', 'r');
$decoded = Bencode::decode(
new FileHandle($file)
);
When I wrote this back in April, it broke backwards compatibility by changing the method signature of Bencode::decode
to require an instance of DataSource
, but I've updated it for this PR to implicitly convert strings to Rych\Bencode\DataSource\String
instead.