Skip to content

Commit 2d0649b

Browse files
committed
do not compress long string by default, read bjd from URI
1 parent 5135dea commit 2d0649b

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

loadbj.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
fid = fopen(fname,'rb');
102102
string = fread(fid,jsonopt('MaxBuffer',inf,opt),'uint8=>char')';
103103
fclose(fid);
104+
elseif(regexpi(fname,'^\s*(http|https|ftp|file)://'))
105+
string = char(webread(fname, weboptions('ContentType','binary')))';
104106
elseif(length(fname) && any(fname(1)=='[{SCHiUIulmLMhdDTFZN'))
105107
string=fname;
106108
else
@@ -183,7 +185,7 @@
183185
catch ME
184186
warning(['Failed to decode embedded JData annotations, '...
185187
'return raw JSON data\n\njdatadecode error: %s\n%s\nCall stack:\n%s\n'], ...
186-
ME.identifier, ME.message, savejson('',ME.stack));
188+
ME.identifier, ME.message, char(savejson('',ME.stack)));
187189
end
188190
end
189191
if(mmaponly)
@@ -458,7 +460,7 @@
458460
end
459461
msg = [sprintf(msg, pos) ': ' ...
460462
inputstr(poShow(1):poShow(2)) '<error>' inputstr(poShow(3):poShow(4)) ];
461-
error( ['JSONLAB:BJData:InvalidFormat: ' msg] );
463+
error('JSONLAB:BJData:InvalidFormat', msg);
462464
end
463465

464466
%%-------------------------------------------------------------------------

loadjson.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@
274274
catch ME
275275
warning(['Failed to decode embedded JData annotations, '...
276276
'return raw JSON data\n\njdatadecode error: %s\n%s\nCall stack:\n%s\n'], ...
277-
ME.identifier, ME.message, savejson('',ME.stack));
277+
ME.identifier, ME.message, char(savejson('',ME.stack)));
278278
end
279279
end
280280
if(opt.mmaponly)
@@ -620,7 +620,7 @@
620620
end
621621
msg = [sprintf(msg, pos) ': ' ...
622622
inputstr(poShow(1):poShow(2)) '<error>' inputstr(poShow(3):poShow(4)) ];
623-
error( ['JSONLAB:JSON:InvalidFormat: ' msg] );
623+
error('JSONLAB:JSON:InvalidFormat', msg);
624624
end
625625

626626
%%-------------------------------------------------------------------------

savebj.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
% 'base64' encoding
9393
% CompressArraySize [100|int]: only to compress an array if the total
9494
% element count is larger than this number.
95-
% CompressStringSize [400|int]: only to compress a string if the total
95+
% CompressStringSize [inf|int]: only to compress a string if the total
9696
% element count is larger than this number.
9797
% MessagePack [0|1]: output MessagePack (https://msgpack.org/)
9898
% binary stream instead of BJD/UBJSON
@@ -172,7 +172,7 @@
172172
opt.nestarray=jsonopt('NestArray',0,opt);
173173
opt.formatversion=jsonopt('FormatVersion',2,opt);
174174
opt.compressarraysize=jsonopt('CompressArraySize',100,opt);
175-
opt.compressstringsize=jsonopt('CompressStringSize',opt.compressarraysize*4,opt);
175+
opt.compressstringsize=jsonopt('CompressStringSize',inf,opt);
176176
opt.singletcell=jsonopt('SingletCell',1,opt);
177177
opt.singletarray=jsonopt('SingletArray',0,opt);
178178
opt.arraytostruct=jsonopt('ArrayToStruct',0,opt);

0 commit comments

Comments
 (0)