+=head2 RecordsFromISO2709File
+
+ my ($errors, $records) = C4::ImportBatch::RecordsFromISO2709File($input_file, $record_type, $encoding);
+
+Reads ISO2709 binary porridge from the given file and creates MARC::Record-objects out of it.
+
+@PARAM1, String, absolute path to the ISO2709 file.
+@PARAM2, String, see stage_file.pl
+@PARAM3, String, should be utf8
+
+Returns two array refs.
+
+=cut
+
+sub RecordsFromISO2709File {
+ my ($input_file, $record_type, $encoding) = @_;
+ my @errors;
+
+ my $marc_type = C4::Context->preference('marcflavour');
+ $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
+
+ open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n";
+ my @marc_records;
+ $/ = "\035";
+ while (<IN>) {
+ s/^\s+//;
+ s/\s+$//;
+ next unless $_; # skip if record has only whitespace, as might occur
+ # if file includes newlines between each MARC record
+ my ($marc_record, $charset_guessed, $char_errors) = MarcToUTF8Record($_, $marc_type, $encoding);
+ push @marc_records, $marc_record;
+ if ($charset_guessed ne $encoding) {
+ push @errors,
+ "Unexpected charset $charset_guessed, expecting $encoding";
+ }
+ }
+ close IN;
+ return ( \@errors, \@marc_records );
+}
+
+=head2 RecordsFromMARCXMLFile
+
+ my ($errors, $records) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding);
+
+Creates MARC::Record-objects out of the given MARCXML-file.
+
+@PARAM1, String, absolute path to the ISO2709 file.
+@PARAM2, String, should be utf8
+
+Returns two array refs.
+
+=cut
+
+sub RecordsFromMARCXMLFile {
+ my ( $filename, $encoding ) = @_;
+ my $batch = MARC::File::XML->in( $filename );
+ my ( @marcRecords, @errors, $record );
+ do {
+ eval { $record = $batch->next( $encoding ); };
+ if ($@) {
+ push @errors, $@;
+ }
+ push @marcRecords, $record if $record;
+ } while( $record );
+ return (\@errors, \@marcRecords);
+}