player/javascript: allow reading partial result for af_push_file

ca7006a6a2 replaced file reading with
stream_read_file which results in error when af_push_file is used
to test existence with 1-byte limit. Fix this by using
STREAM_ALLOW_PARTIAL_READ flag to restore the old loading behavior.
This commit is contained in:
nanahi 2024-10-21 01:09:50 -04:00 committed by Avi Halachmi
parent dd23bf1555
commit 2af0b0b34b
1 changed files with 6 additions and 1 deletions

View File

@ -351,7 +351,12 @@ static void af_push_file(js_State *J, const char *fname, int limit, void *af)
return;
}
bstr data = stream_read_file(filename, af, jctx(J)->mpctx->global, limit);
// mp.utils.read_file allows partial read up to limit which results in
// error for stream_read_file if the file is larger than limit, so use
// STREAM_ALLOW_PARTIAL_READ to allow reading returning partial results.
int flags = STREAM_READ_FILE_FLAGS_DEFAULT | STREAM_ALLOW_PARTIAL_READ;
bstr data = stream_read_file2(filename, af, flags,
jctx(J)->mpctx->global, limit);
if (data.start) {
js_pushlstring(J, data.start, data.len);
} else {