From: Aaron Patterson Date: 2012-02-09T02:11:11+09:00 Subject: [ruby-core:42441] Re: [ruby-trunk - Bug #5978][Open] YAML.load_stream should process documents as they are read --tKW2IUtsqtDRztdT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 08, 2012 at 01:47:31AM +0900, Thomas Sawyer wrote: >=20 > Issue #5978 has been reported by Thomas Sawyer. >=20 > ---------------------------------------- > Bug #5978: YAML.load_stream should process documents as they are read > https://bugs.ruby-lang.org/issues/5978 >=20 > Author: Thomas Sawyer > Status: Open > Priority: Normal > Assignee:=20 > Category:=20 > Target version: 2.0.0 > ruby -v: ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux] >=20 >=20 > Psych say YAML.load_documents is deprecated and say to use `YAML.load_str= eam` instead. >=20 > Looking at the implementation for `load_stream()`, looks to me as if it w= aits for all documents in the stream to load before anything can be done wi= th it. >=20 > # File 'lib/psych.rb', line 221 >=20 > def self.load_stream yaml > parse_stream(yaml).children.map { |child| child.to_ruby } > end >=20 > I don't think this should be the case. Ideally `load_stream()` would take= a block, and if an IO object is given, read a document, yield it and then = read the next document, and so on. >=20 > I imagine an Enumerator might be applicable to this as well. I'd rather not change `load_stream`, but I want this functionality as well. What about something like this: YAML::Reader.new(io).each do |doc| ... end Deserialized documents will be yielded as read. Does that seem acceptable? I'm hesitant to make it enumerable though because if we're truly doing stream processing, you couldn't iterate on the same object twice (imagine reading YAML from a socket or something). --=20 Aaron Patterson http://tenderlovemaking.com/ --tKW2IUtsqtDRztdT Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) iQEcBAEBAgAGBQJPMqypAAoJEJUxcLy0/6/GVMQH/0RtH1S1eV4/67Bzc0MU8vnD l6qDUKfaVX7mZpYdUAfJ/uMzdMMTA8PV8UUnMjsjyqFuXWT8PrqBBj2GKja9mAIQ 1UKSkcvv7TOuiLBh6MZWG+Tggy8MPKVYToT5KGiddavNfsmMu5wSQw4iml27f0BT paJxh7TljmWrTihbPferKE99mSg2FFrm54B+TnDoXtrSmg0q4nSITSwpozNr+TBM 3ZWIkG+zmZ4K1Dm8QhIV5dvtXmAxbAMkWXX8Bdcm40S8knA1V+/bFIiIsi5I21Xn 54emRMTGMtAEmTM4cmPnUzYXvt1FiG9+KaOIY6XLSFDBUfIA8Ypq1pD++EyAfa0= =/b8H -----END PGP SIGNATURE----- --tKW2IUtsqtDRztdT--