Commit be36ad02 authored by Julien Lepiller's avatar Julien Lepiller

torrent: Use a list for torrent-info-pieces.

* torrent/metainfo.scm (parse-info): Split pieces into a list.
parent de0ba978
......@@ -72,16 +72,25 @@
(assoc-ref file "len")
(map (lambda (p) (utf8->string p))(assoc-ref file "path")))))
(define (split-pieces pieces)
(let loop ((offset 0) (result '()))
(if (>= offset (bytevector-length pieces))
result
(begin
(let ((bv (make-bytevector 20 0)))
(bytevector-copy! pieces offset bv 0 20)
(loop (+ offset 20) (cons bv result)))))))
(define (parse-info info)
(let* ((info (dictionnary-alist info))
(single-file? (not (assoc-ref info "files"))))
(make-torrent-info
(assoc-ref info "piece-length")
(assoc-ref info "pieces")
(assoc-ref info "piece length")
(split-pieces (assoc-ref info "pieces"))
(assoc-ref info "private")
single-file?
(assoc-ref info "name")
(assoc-ref info "len")
(assoc-ref info "length")
(if single-file? #f
(map parse-file (assoc-ref info "files"))))))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment