When reading a file from KVS, there is no way to know the file extension beforehand. So the system first tries to look for common file extensions and if that does not work, it lists the full contents of the directory.
The problem is, when using streams with createReadStream as the handler, an ENOENT error is not thrown until we start reading the stream. So the file extension immediately resolves to json even if that's not true. Later the read fails with ENOENT.
We could hotfix it by always using the full lookup with streams, but I think it makes sense to spend a few minutes trying to come up with a better solution.
When reading a file from KVS, there is no way to know the file extension beforehand. So the system first tries to look for common file extensions and if that does not work, it lists the full contents of the directory.
The problem is, when using streams with
createReadStream
as the handler, an ENOENT error is not thrown until we start reading the stream. So the file extension immediately resolves tojson
even if that's not true. Later the read fails with ENOENT.We could hotfix it by always using the full lookup with streams, but I think it makes sense to spend a few minutes trying to come up with a better solution.
https://github.com/apify/apify-storage-local-js/blob/1d8c9d5692f26cb79bc455456d874c81ea887fae/src/resource_clients/key_value_store.ts#L325-L334