Skip to content

Commit

Permalink
do not compress long string by default, read bjd from URI
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Jun 11, 2023
1 parent 5135dea commit 2d0649b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions loadbj.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
fid = fopen(fname,'rb');
string = fread(fid,jsonopt('MaxBuffer',inf,opt),'uint8=>char')';
fclose(fid);
elseif(regexpi(fname,'^\s*(http|https|ftp|file)://'))
string = char(webread(fname, weboptions('ContentType','binary')))';
elseif(length(fname) && any(fname(1)=='[{SCHiUIulmLMhdDTFZN'))
string=fname;
else
Expand Down Expand Up @@ -183,7 +185,7 @@
catch ME
warning(['Failed to decode embedded JData annotations, '...
'return raw JSON data\n\njdatadecode error: %s\n%s\nCall stack:\n%s\n'], ...
ME.identifier, ME.message, savejson('',ME.stack));
ME.identifier, ME.message, char(savejson('',ME.stack)));
end
end
if(mmaponly)
Expand Down Expand Up @@ -458,7 +460,7 @@
end
msg = [sprintf(msg, pos) ': ' ...
inputstr(poShow(1):poShow(2)) '<error>' inputstr(poShow(3):poShow(4)) ];
error( ['JSONLAB:BJData:InvalidFormat: ' msg] );
error('JSONLAB:BJData:InvalidFormat', msg);
end

%%-------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions loadjson.m
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
catch ME
warning(['Failed to decode embedded JData annotations, '...
'return raw JSON data\n\njdatadecode error: %s\n%s\nCall stack:\n%s\n'], ...
ME.identifier, ME.message, savejson('',ME.stack));
ME.identifier, ME.message, char(savejson('',ME.stack)));
end
end
if(opt.mmaponly)
Expand Down Expand Up @@ -620,7 +620,7 @@
end
msg = [sprintf(msg, pos) ': ' ...
inputstr(poShow(1):poShow(2)) '<error>' inputstr(poShow(3):poShow(4)) ];
error( ['JSONLAB:JSON:InvalidFormat: ' msg] );
error('JSONLAB:JSON:InvalidFormat', msg);
end

%%-------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions savebj.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
% 'base64' encoding
% CompressArraySize [100|int]: only to compress an array if the total
% element count is larger than this number.
% CompressStringSize [400|int]: only to compress a string if the total
% CompressStringSize [inf|int]: only to compress a string if the total
% element count is larger than this number.
% MessagePack [0|1]: output MessagePack (https://msgpack.org/)
% binary stream instead of BJD/UBJSON
Expand Down Expand Up @@ -172,7 +172,7 @@
opt.nestarray=jsonopt('NestArray',0,opt);
opt.formatversion=jsonopt('FormatVersion',2,opt);
opt.compressarraysize=jsonopt('CompressArraySize',100,opt);
opt.compressstringsize=jsonopt('CompressStringSize',opt.compressarraysize*4,opt);
opt.compressstringsize=jsonopt('CompressStringSize',inf,opt);
opt.singletcell=jsonopt('SingletCell',1,opt);
opt.singletarray=jsonopt('SingletArray',0,opt);
opt.arraytostruct=jsonopt('ArrayToStruct',0,opt);
Expand Down

0 comments on commit 2d0649b

Please sign in to comment.