pin / tftp

TFTP server and client library for Golang
MIT License
287 stars 71 forks source link

Allow for custom block size in client #38

Closed earlgreyz closed 6 years ago

earlgreyz commented 6 years ago

Test plan

First downloaded the file with standard tftp client

busybox tftp -g -r /file "example.com:69" -b 1024

And then used a simple go program to do the same

package main

import (
    "github.com/pin/tftp"
    "os"
)

const target = "example.com:69"
const blksize = 1024
const filename = "/file"
const output = "/tmp/file"

func main() {
    c, err := tftp.NewClient(target)
    if err != nil {
        panic(err)
    }
    f, err := os.Create(output)
    if err != nil {
        panic(err)
    }
    defer f.Close()
    c.SetBlksize(blksize)
    w, err := c.Receive(filename, "octet")
    if err != nil {
        panic(err)
    }
    _, err = w.WriteTo(f)
    if err != nil {
        panic(err)
    }
}

And standard diff

diff -s file /tmp/file
Files file and /tmp/file are identical
pallotron commented 6 years ago

@pin would it be possible to merge this? :)

pin commented 6 years ago

@earlgreyz, @pallotron thank you for this PR, also appreciate fixing error message in test.

My concern is setBlksize method name, could it be setBlockSize to be slightly more self-descriptive?

Going to merge now and will contact you in regards to method rename.