Adds capabilities to import a .zip file with importZip.
Detects the content type of source by checking bytes & DetectContentType.
Adds LimitedReader reader, a fork of io.LimitedReader,
was needed for better error messaging instead of just getting back EOF.
We are using limited reader to avoid very big files causing memory issues.
Adds a new file size limit for context imports,
this limit is used for the main file for .zip & .tar and individual compressed
files for .zip.
Added TestImportZip that will check the import content type
Then will assert no err on Importing .zip file
Signed-off-by: Goksu Toprak <goksu.toprak@docker.com>
(cherry picked from commit 291e86289b)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
25 lines
472 B
Go
25 lines
472 B
Go
package store
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gotest.tools/assert"
|
|
)
|
|
|
|
func TestLimitReaderReadAll(t *testing.T) {
|
|
r := strings.NewReader("Reader")
|
|
|
|
_, err := ioutil.ReadAll(r)
|
|
assert.NilError(t, err)
|
|
|
|
r = strings.NewReader("Test")
|
|
_, err = ioutil.ReadAll(&LimitedReader{R: r, N: 4})
|
|
assert.NilError(t, err)
|
|
|
|
r = strings.NewReader("Test")
|
|
_, err = ioutil.ReadAll(&LimitedReader{R: r, N: 2})
|
|
assert.Error(t, err, "read exceeds the defined limit")
|
|
}
|