66
77import  os 
88import  warnings 
9+ from  contextlib  import  suppress 
910
1011import  numpy  as  np 
1112
@@ -331,6 +332,8 @@ def _read_header(cls, fileobj):
331332            f .seek (1 , os .SEEK_CUR )  # Skip \n 
332333
333334            found_end  =  False 
335+             key  =  None 
336+             tmp_hdr  =  {}
334337
335338            # Read all key-value pairs contained in the header, stop at EOF 
336339            for  n_line , line  in  enumerate (f , 1 ):
@@ -343,15 +346,22 @@ def _read_header(cls, fileobj):
343346                    found_end  =  True 
344347                    break 
345348
346-                 if  ':'  not  in   line :  # Invalid header line 
349+                 # Set new key if available, otherwise append to last known key 
350+                 with  suppress (ValueError ):
351+                     key , line  =  line .split (':' , 1 )
352+                     key  =  key .strip ()
353+ 
354+                 # Apparent continuation line before any keys are found 
355+                 if  key  is  None :
347356                    raise  HeaderError (f'Invalid header (line { n_line }  ): { line }  ' )
348357
349-                 key , value  =  line .split (':' , 1 )
350-                 hdr [key .strip ()] =  value .strip ()
358+                 tmp_hdr .setdefault (key , []).append (line .strip ())
351359
352360            if  not  found_end :
353361                raise  HeaderError ('Missing END in the header.' )
354362
363+             hdr .update ({key : '\n ' .join (val ) for  key , val  in  tmp_hdr .items ()})
364+ 
355365            offset_data  =  f .tell ()
356366
357367            # Set the file position where it was, in case it was previously open 
0 commit comments