diff --git a/conversion_test.go b/conversion_test.go index 2fa03e1b..65acfd6a 100644 --- a/conversion_test.go +++ b/conversion_test.go @@ -2,6 +2,7 @@ package go2com import ( "fmt" + "github.com/okieraised/go2com/internal/utils" "github.com/stretchr/testify/assert" "os" "testing" @@ -26,3 +27,71 @@ func TestParser_Export(t *testing.T) { mapTagVal := parser.Export(false) fmt.Println(mapTagVal) } + +func TestParser_Buffer(t *testing.T) { + assert := assert.New(t) + InitTagDict() + file, err := os.Open("/home/tripg/workspace/dicom_buffer/D4CDC297.dcm") + assert.NoError(err) + + defer file.Close() + info, err := file.Stat() + assert.NoError(err) + fileSize := info.Size() + + parser, err := NewParser(file, fileSize, false, false) + assert.NoError(err) + err = parser.Parse() + assert.NoError(err) + + mapTagVal := parser.Export(false) + fmt.Println(mapTagVal) +} + +func TestParser_MultipleFiles(t *testing.T) { + + assert := assert.New(t) + + filePaths, err := utils.ReadDirRecursively("/home/tripg/workspace/dicom/test_data") + assert.NoError(err) + InitTagDict() + for _, fPath := range filePaths { + fmt.Println("process:", fPath) + file, err := os.Open(fPath) + assert.NoError(err) + + defer file.Close() + info, err := file.Stat() + assert.NoError(err) + fileSize := info.Size() + + parser, err := NewParser(file, fileSize, false, false) + assert.NoError(err) + err = parser.Parse() + assert.NoError(err) + } +} + +func TestParser_MultipleFiles_2(t *testing.T) { + + assert := assert.New(t) + + filePaths, err := utils.ReadDirRecursively("/home/tripg/workspace/dicom/test_full") + assert.NoError(err) + InitTagDict() + for _, fPath := range filePaths { + fmt.Println("process:", fPath) + file, err := os.Open(fPath) + assert.NoError(err) + + defer file.Close() + info, err := file.Stat() + assert.NoError(err) + fileSize := info.Size() + + parser, err := NewParser(file, fileSize, false, false) + assert.NoError(err) + err = parser.Parse() + assert.NoError(err) + } +} diff --git a/parse.go b/parse.go index 6bb9073f..6c686f16 100644 --- a/parse.go +++ b/parse.go @@ -32,7 +32,8 @@ func InitTagDict() { // NewParser returns a new dicom parser func NewParser(fileReader io.Reader, fileSize int64, skipPixelData, skipDataset bool) (*Parser, error) { - dcmReader := reader.NewDcmReader(bufio.NewReader(fileReader), skipPixelData) + bufReader := bufio.NewReaderSize(fileReader, 4<<20) + dcmReader := reader.NewDcmReader(bufReader, skipPixelData) parser := Parser{ skipPixelData: skipPixelData, skipDataset: skipDataset,