Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IO::Handle-like $body -- why getline(), not read() #5

Closed
miyagawa opened this issue Sep 9, 2009 · 2 comments
Closed

IO::Handle-like $body -- why getline(), not read() #5

miyagawa opened this issue Sep 9, 2009 · 2 comments

Comments

@miyagawa
Copy link
Member

miyagawa commented Sep 9, 2009

confound pointed out that $fh as a file handle might not work if it's not line-ending, or performance poorly. Can we let them support read instead? Or let implementors to specify a callback that app can optionally set file handle back (like the case of AnyEvent?)

Duck typing read() and getline() on perl objects and filehandles are hard.

From PEP333:

Some operating environments provide special high-performance file- transmission facilities, such as the Unix sendfile() call. Servers and gateways may expose this functionality via an optional wsgi.file_wrapper key in the environ. An application may use this "file wrapper" to convert a file or file-like object into an iterable that it then returns, e.g.:

if 'wsgi.file_wrapper' in environ:
return environ['wsgi.file_wrapper'](filelike, block_size)
else:
return iter(lambda: filelike.read(block_size), '')

To be considered "file-like", the object supplied by the application must have a read() method that takes an optional size argument. It may have a close() method, and if so, the iterable returned by wsgi.file_wrapper must have a close() method that invokes the original file-like object's close() method.

@miyagawa
Copy link
Member Author

13:12 tiarra: 13:11:26 >miyagawa< yay
13:12 tiarra: 13:11:26 >miyagawa< so I talked with nothingmuch for like half an hour
13:13 miyagawa: getline is kept. read is not because it's not easy to write read() mock
13:13 Mode: +n
13:13 Created at: 2008/04/30 00:02
13:13 miyagawa: but getline is
13:13 miyagawa: and if backends want to read binary then just use fileno to check if it's a real filehandle
13:13 miyagawa: and/or do local $/ = $bytes; to do chunking

@miyagawa
Copy link
Member Author

feedback merged.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant