Commit ae955d43 authored by Nemanja Zbiljić's avatar Nemanja Zbiljić Committed by GitHub

Validate write operation expected result (#566)

parent 2ab40671
......@@ -54,10 +54,13 @@ func (c *ChunkPipe) Write(b []byte) (int, error) {
if c.cursor >= swarm.ChunkSize {
// NOTE: the Write method contract requires all sent data to be
// written before returning (without error)
_, err := c.writer.Write(c.data[:swarm.ChunkSize])
written, err := c.writer.Write(c.data[:swarm.ChunkSize])
if err != nil {
return nw, err
}
if swarm.ChunkSize != written {
return nw, io.ErrShortWrite
}
c.cursor -= swarm.ChunkSize
......@@ -71,10 +74,13 @@ func (c *ChunkPipe) Write(b []byte) (int, error) {
// Close implements io.Closer
func (c *ChunkPipe) Close() error {
if c.cursor > 0 {
_, err := c.writer.Write(c.data[:c.cursor])
written, err := c.writer.Write(c.data[:c.cursor])
if err != nil {
return err
}
if c.cursor != written {
return io.ErrShortWrite
}
}
return c.writer.Close()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment