Hi Inna,
How about if we just added:
attr_reader :handle
to MARC::Reader?
Then you should be able to do:
marc = MARC::Reader.new(open('file.mrc'))
marc.each do |rec|
...
end
marc.handle.close
I'm not sure that MARC::Reader can be passed an object that doesn't respond to close, but this way we don't have to worry about it (plus you'll have access to the rest of IO, like .rewind, etc., as well).
Anybody have any objections to this?
Also, it would probably make sense to update the readme to move discussion to Github's ticket system rather than here...
Thanks!
-Ross.
On Sep 12, 2012, at 6:37 PM, Inna Ilinskaya <[log in to unmask]> wrote:
> On http://marc.rubyforge.org/ page it's recommended that requests for
> gem 'marc' are sent to this mailing list :)
>
> I noticed that Class: MARC::Reader does not close the file after reading
> from it. And there is no close method available for this class.
>
> I have a script that loads file from ftp, reads from it using
> MARC::Reader and then deletes file. When I try to delete the file, I get
> "Permissions denied" error message, since the file was left open after I
> read from it.
>
> It will be beneficial if explicit close method is implemented for
> MARC::Reader.
>
> The workaround is to open the file via File object first, e.g.,
>
> fh = File.new("C:/temp/test.mrc")
> r = MARC::Reader.new(fh)
> ...
> fh.close
>
> Thank you so much!!!
>
> Inna
|