This is an archive of the discontinued Mercurial Phabricator instance.

util: add a file object proxy that can read at most N bytes
ClosedPublic

Authored by indygreg on Feb 21 2018, 5:07 PM.

Details

Summary

Sometimes we have data of a known size within a stream. For
performance reasons, we don't want to pre-read this data (we want
to allow consumers to read on demand). For simplicitly reasons,
we don't want callers to necessarily know their data is coming
from within an outer stream and there is a limit to how much
they should read.

The class introduced by this commit provides a very simple proxy
around an underlying file object that allows the consumer to
.read() up to N bytes from the file object. Attempts to read
past this many bytes results in a simulated EOF.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

indygreg created this revision.Feb 21 2018, 5:07 PM
lothiraldan accepted this revision.Feb 22 2018, 3:14 AM
lothiraldan added a subscriber: lothiraldan.

LGTM

yuja accepted this revision.Feb 22 2018, 9:05 AM
This revision is now accepted and ready to land.Feb 22 2018, 9:05 AM
This revision was automatically updated to reflect the committed changes.