@@ -124,6 +124,7 @@ type WriteCounter struct {
124
124
Total uint64
125
125
connection * net.Conn
126
126
expectedLength uint64
127
+ writer * io.PipeWriter
127
128
}
128
129
// func reverseBytes(input []byte) []byte {
129
130
// if len(input) == 0 {
@@ -143,7 +144,9 @@ func (wc *WriteCounter) Write(p []byte) (int, error) {
143
144
binary .Write ((* wc .connection ), binary .BigEndian , buf .Bytes ()[4 :8 ])
144
145
145
146
}
146
-
147
+ if wc .expectedLength == wc .Total {
148
+ (* wc .writer ).Close ()
149
+ }
147
150
return n , nil
148
151
}
149
152
@@ -172,6 +175,7 @@ func serveFile(parts ParsedParts, w http.ResponseWriter, r *http.Request) (work
172
175
connection :& conn ,
173
176
Total : 0 ,
174
177
expectedLength : parts .length ,
178
+ writer : pw ,
175
179
}
176
180
177
181
@@ -184,8 +188,8 @@ func serveFile(parts ParsedParts, w http.ResponseWriter, r *http.Request) (work
184
188
}
185
189
w .Header ().Set ("Content-Length" , strconv .Itoa (intLength ) /*r.Header.Get("Content-Length")*/ )
186
190
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 )
189
193
//stream the body to the client without fully loading it into memory
190
194
// pbw := bufio.NewWriter(conn)
191
195
// pbr := bufio.NewReader(conn)
@@ -264,7 +268,6 @@ func DCCSend(hook *webircgateway.HookIrcLine) {
264
268
}
265
269
266
270
configs .server .AddFile (parts .file , * parts )
267
- log .Printf (parts .file )
268
271
269
272
client .SendClientSignal ("data" , hook .Message .ToLine ())
270
273
}
0 commit comments