Code Monkey home page Code Monkey logo

rapidyenc's People

Contributors

mnightingale avatar

Stargazers

 avatar  avatar

Watchers

 avatar

rapidyenc's Issues

How to use to decode a segment

First of all, nice work here ;).

I´m trying to use the library to decode a yenc segment but I always end up with an transform.ErrShortSrc.

The segments that I get are encoded following this code:

`go
buf := &bytes.Buffer{}
buf.WriteString(fmt.Sprintf("From: %s\r\n", data.poster))
buf.WriteString(fmt.Sprintf("Newsgroups: %s\r\n", data.group))
buf.WriteString(fmt.Sprintf("Message-ID: <%s>\r\n", data.msgId))
buf.WriteString("X-Newsposter: xxxxx\r\n")

// Build subject
subj := fmt.Sprintf(
	"[%d/%d] - \"%s\" yEnc (%d/%d)",
	data.fileNum,
	data.fileTotal,
	data.fileName,
	data.partNum,
	data.partTotal,
)
buf.WriteString(fmt.Sprintf("Subject: %s\r\n\r\n", subj))

// yEnc begin line
// yEnc begin line
buf.WriteString(fmt.Sprintf(
	"=ybegin part=%d total=%d line=128 size=%d name=%s\r\n",
	data.partNum,
	data.partTotal,
	data.fileSize,
	data.fileName,
))
// yEnc part line
buf.WriteString(fmt.Sprintf("=ypart begin=%d end=%d\r\n", data.partBegin+1, data.partEnd))

// Encoded data
err := yenc.Encode(p, buf)
if err != nil {
	return nil, err
}
// yEnc end line
h := crc32.NewIEEE()
h.Write(p)
buf.WriteString(fmt.Sprintf("=yend size=%d part=%d pcrc32=%08X\r\n", data.partSize, data.partNum, h.Sum32()))

`

Then I just decode it by input the segment read from the Usenet provider.
Like here https://github.com/javi11/usenet-drive/blob/dbb86388ad2648590442335512c8dd6f90b37212/internal/usenet/filereader/buffer.go#L289. Right now I´m using another implementation of yenc decoder.

Could you please guide on how to use the library?

Thanks

Negative numbers on yend that make the library crash

Hey, there is a special case that is causing me an error using the library:

I see that when src Is equals to yend size=750000 part=8525 pcrc32=ACBE5763\r\n.\r\n
The values returned by decodedDecremental are
nd: 0 ns: 1 end: 1

With these values, this part of the code:

case EndControl:
,
decrements the ns - 2 making it negative number and therefore the library crash with:

panic: runtime error: slice bounds out of range [-1:] goroutine 474 [running]: github.com/mnightingale/rapidyenc.(*Decoder).Transform(0xc0002465a0, {0xc002af3000, 0x1000, 0x1000}, {0xc000172000, 0x2c, 0x1000}, 0x0) /go/pkg/mod/github.com/mnightingale/[email protected]/decoder.go:206 +0x915 github.com/mnightingale/rapidyenc.(*Decoder).Read(0xc0002465a0, {0xc0045651b0, 0x20e50, 0xc0002465a0?}) /go/pkg/mod/github.com/mnightingale/[email protected]/decoder.go:142

I solved by adding a check after the switch case in which
if nSrc < 0 { return nDst, 1, io.EOF }

But not sure if is correct or not because I don't fully understand the code. Do you think is a good solution? I can do a pr for it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.