all repos — captcha @ ad3bc714999c41d5d354dc1fc7087ac2a484859a

Go package captcha implements generation and verification of image and audio CAPTCHAs.

audio: write pad byte when data length is odd.

This is specified in RIFF format, but I forgot to implement.

     ckData  Binary data of fixed or variable size. The start of
	     ckData is word-aligned with respect to the start of the
	     RIFF file.  If the chunk size is an odd number of bytes, a
	     pad byte with value zero is written after ckData.  Word
	     aligning improves access speed (for chunks resident in
	     memory) and maintains compatibility with EA IFF.  The
	     ckSize value does not include the pad byte.

(From http://www.kk.iij4u.or.jp/~kondo/wave/mpidata.txt)
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 01 May 2011 12:33:27 +0200
commit

ad3bc714999c41d5d354dc1fc7087ac2a484859a

parent

796c18f35a497838983c1922e846c7d92b0e0470

1 files changed, 9 insertions(+), 0 deletions(-)

jump to
M audio.goaudio.go

@@ -86,18 +86,27 @@

// WriteTo writes captcha audio in WAVE format into the given io.Writer, and // returns the number of bytes written and an error if any. func (a *Audio) WriteTo(w io.Writer) (n int64, err os.Error) { + // Header. nn, err := w.Write(waveHeader) n = int64(nn) if err != nil { return } + // Chunk length. err = binary.Write(w, binary.LittleEndian, uint32(a.body.Len())) if err != nil { return } nn += 4 + // Chunk data. n, err = a.body.WriteTo(w) n += int64(nn) + // Pad byte if chunk length is odd. + // (As header has even length, we can check if n is odd, not chunk). + if n % 2 != 0 { + w.Write([]byte{128}) + n++ + } return }