code: func (info *Info) GeneratePieces(open func(fi FileInfo) (io.ReadCloser, error)) error {
  	if info.PieceLength == 0 {
  		return errors.New("piece length must be non-zero")
  	}
  	pr, pw := io.Pipe()
  	go func() {
  		err := info.writeFiles(pw, open)
  		pw.CloseWithError(err)
  	}()
  	defer pr.Close()
  	var pieces []byte
  	for {
  		hasher := sha1.New()
  		wn, err := io.CopyN(hasher, pr, info.PieceLength)
  		if err == io.EOF {
  			err = nil
  		}
  		if err != nil {
  			return err
  		}
  		if wn == 0 {
  			break
  		}
  		pieces = hasher.Sum(pieces)
  		if wn < info.PieceLength {
  			break
  		}
  	}
  	info.Pieces = pieces
  	return nil
  }
docs: // Sets Pieces (the block of piece hashes in the Info) by using the passed
  // function to get at the torrent data.