@@ -638,19 +638,17 @@ onnx.Tensor = class {
638
638
}
639
639
case onnx . DataLocation . EXTERNAL : {
640
640
if ( Array . isArray ( tensor . external_data ) ) {
641
- const external_data = { } ;
641
+ const data = new Map ( ) ;
642
642
for ( const entry of tensor . external_data ) {
643
- external_data [ entry . key ] = entry . value ;
643
+ data . set ( entry . key , entry . value ) ;
644
644
}
645
- if ( external_data . location && external_data . offset && external_data . length ) {
646
- this . _location = external_data . location . toString ( ) ;
647
- const offset = parseInt ( external_data . offset , 10 ) ;
648
- const length = parseInt ( external_data . length , 10 ) ;
649
- if ( Number . isInteger ( offset ) && Number . isInteger ( length ) ) {
650
- const location = context . location ( external_data . location ) ;
651
- this . _request = { location, offset, length } ;
652
- this . _encoding = '<' ;
653
- }
645
+ if ( data . has ( 'location' ) ) {
646
+ this . _location = data . get ( 'location' ) . toString ( ) ;
647
+ const location = context . location ( this . _location ) ;
648
+ const offset = data . has ( 'offset' ) ? parseInt ( data . get ( 'offset' ) , 10 ) : 0 ;
649
+ const length = data . has ( 'length' ) ? parseInt ( data . get ( 'length' ) , 10 ) : - 1 ;
650
+ this . _request = { location, offset, length } ;
651
+ this . _encoding = '<' ;
654
652
}
655
653
}
656
654
break ;
@@ -3002,6 +3000,7 @@ onnx.Location = class {
3002
3000
const stream = content . stream ;
3003
3001
const position = stream . position ;
3004
3002
stream . seek ( offset ) ;
3003
+ length = length === - 1 ? stream . length - offset : length ;
3005
3004
content = stream . stream ( length ) ;
3006
3005
stream . seek ( position ) ;
3007
3006
this . content . set ( key , content ) ;
0 commit comments