-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using metainfo.NewInfoFromFilePath on a directory results in "error copying" #1
Comments
Thank you for your test! It is a bug when reading a directory to create a new
For the new command func CreateTorrent(ctx *cli.Context) error {
dirs := ctx.Args().Slice()
if len(dirs) > 1 {
return fmt.Errorf("Input invalid, please use only one file or directory at ta time.")
}
info, err := metainfo.NewInfoFromFilePath(dirs[0], int64(ctx.Int("length")))
if err != nil {
return err
}
var mi metainfo.MetaInfo
mi.InfoBytes, err = bencode.EncodeBytes(info)
if err != nil {
return err
}
// Set the announce information.
announces := ctx.StringSlice("announce")
switch len(announces) {
case 0:
case 1:
mi.Announce = announces[0]
default:
mi.AnnounceList = metainfo.AnnounceList{announces}
}
/// TODO: set the webseed information like above.
/// TODO: set other fields of MetaInfo.
var output io.WriteCloser = os.Stdout
if o := ctx.String("output"); o != "" {
output, err = os.OpenFile(o, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
}
defer output.Close()
}
return mi.Write(output)
} |
I see, that helps a lot. Changed my implementation to match the correct way to use the Info and now the create command works! Sent a PR over in bttools, looking forward to hearing from you there. |
The bug has been fixed. See Release v0.4.1. |
I am attempting to learn your library and am getting started by writing a .torrent file generation tool for your bttools suite. I am attempting to produce the bytes required to populate the
metainfo.MetaInfo.InfoBytes
field by creating the metainfo.Info object usingmetainfo.NewInfoFromFilePath
function on a directory, then loop over the pieces and concatenate them together. This approach works if I'm creating a single-file torrent, but when I try to create a multi-file torrent from a directory, I get:You can see the code here:
xgfone/bttools@master...eyedeekay:create
The documentation says
NewInfoFromFilePath returns a new Info from a file or directory
so I think this must be unintentional, or I am misusing the function.Thanks in advance for your help.
The text was updated successfully, but these errors were encountered: