Skip to content

Commit 30288f0

Browse files
close
1 parent 0478d61 commit 30288f0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

xdcc/xdcc.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ type WriteCounter struct {
124124
Total uint64
125125
connection *net.Conn
126126
expectedLength uint64
127+
writer *io.PipeWriter
127128
}
128129
// func reverseBytes(input []byte) []byte {
129130
// if len(input) == 0 {
@@ -143,7 +144,9 @@ func (wc *WriteCounter) Write(p []byte) (int, error) {
143144
binary.Write((*wc.connection), binary.BigEndian, buf.Bytes()[4:8])
144145

145146
}
146-
147+
if wc.expectedLength == wc.Total{
148+
(*wc.writer).Close()
149+
}
147150
return n, nil
148151
}
149152

@@ -172,6 +175,7 @@ func serveFile(parts ParsedParts, w http.ResponseWriter, r *http.Request) (work
172175
connection :&conn,
173176
Total: 0,
174177
expectedLength: parts.length,
178+
writer: pw,
175179
}
176180

177181

@@ -184,8 +188,8 @@ func serveFile(parts ParsedParts, w http.ResponseWriter, r *http.Request) (work
184188
}
185189
w.Header().Set("Content-Length", strconv.Itoa(intLength) /*r.Header.Get("Content-Length")*/)
186190

187-
go io.Copy(pw, io.TeeReader( conn,counter))
188-
io.Copy(w, pr)
191+
go io.Copy(pw, io.TeeReader( conn,w))
192+
io.Copy(counter, pr)
189193
//stream the body to the client without fully loading it into memory
190194
// pbw := bufio.NewWriter(conn)
191195
// pbr := bufio.NewReader(conn)
@@ -264,7 +268,6 @@ func DCCSend(hook *webircgateway.HookIrcLine) {
264268
}
265269

266270
configs.server.AddFile(parts.file, *parts)
267-
log.Printf(parts.file)
268271

269272
client.SendClientSignal("data", hook.Message.ToLine())
270273
}

0 commit comments

Comments
 (0)