bencode icon indicating copy to clipboard operation
bencode copied to clipboard

Allow decoding from a file handle

Open stecman opened this issue 10 years ago • 0 comments

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.

stecman avatar Dec 12 '14 00:12 stecman