Highlighted

tFileUnarchive - How to know if the zip is invalid or has no entries?

Hello,
I have a question concerning the tFileUnarchiveComponent.  I'm using it on some zip files, some of which may be invalid and some of which may have no entries.  I would like to link to a component when an invalid zip file is encountered and I'd like to know if there are no rows (ie. no files) from a particular zip.
(Surprisingly, the onComponentError flow is not activated when there is an invalid zip.)
I'd be very grateful for any links to solutions or ideas for alternatives...
Thanks!
13 REPLIES
Moderator

Re: tFileUnarchive - How to know if the zip is invalid or has no entries?

Hi,
Could you please take a look at component TalendHelpCenter:tFileProperties which obtains information about the main properties of a defined file.
There is  a "size" schema (the file size in bytes). You can use it to check your invalid file with no entry(the file size should be 0).
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.

Re: tFileUnarchive - How to know if the zip is invalid or has no entries?

Hi Sabrina,
Thanks for the reply.  So I can use this component to determine if a zip file is empty.  But what if a zip file is corrupt and can't be opened by the tFileUnarchive component?  Is there any way of knowing this?  The component logs an error but the onComponentError does not seem to be called when the archive is invalid...  
François
Moderator

Re: tFileUnarchive - How to know if the zip is invalid or has no entries?

Hi,
What's kind of component error message you are getting?
OnComponentError will trigger the sub-job or component as soon as an error is encountered in the primary Job
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.

Re: tFileUnarchive - How to know if the zip is invalid or has no entries?

When using a corrupt zip, the tFileUnarchive component writes "archive is not a ZIP archive" in the log.  If "Check the integrity before unzip" is checked then it writes "The file <xxx> is corrupted, process terminated..." to the log.
But in neither case is the onComponentError triggered.  I was expecting to be able to use that trigger to determine that an archive is invalid...
Thanks,
François
Ten Stars

Re: tFileUnarchive - How to know if the zip is invalid or has no entries?

I was able to trigger onComponentError execution by checking "Die on Error" in tFileUnarchive's settings. Will that help you?

Re: tFileUnarchive - How to know if the zip is invalid or has no entries?

Thanks.  That would be logical.  I tried that but am still just getting an error in the log and the onComponentError does not get triggered.  Maybe I'm missing some global configuration - will look into that possibility...
Thanks again.
Moderator

Re: tFileUnarchive - How to know if the zip is invalid or has no entries?

Hi François.
Is there any update for your issue?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.

Re: tFileUnarchive - How to know if the zip is invalid or has no entries?

Hi Sabrina,
I tried cterenzi's solution but if I check "Die on error" the onComponentError still does not get triggered.  Is this behavior that can be configured?
Regards,
François
Moderator

Re: tFileUnarchive - How to know if the zip is invalid or has no entries?

Hi,
Would you mind sending an invalid zip file(corrupt, can not open by tFileUnarchive component)to us? In this way, we can make a simple testing for your use case.
Is your job design:tFileUnarchive-->oncomponenterror-->tfileinputproperties?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.

Re: tFileUnarchive - How to know if the zip is invalid or has no entries?

I use any file that is not a zip file (e.g. the one attached).  The tFileUnarchive component logs "archive is not a ZIP archive" when "Check the integrity before unzip" is unchecked.  When that option is checked then I get "The file C:/tools/talend_workspace/archive.zip is corrupted, process terminated...".
In neither case does the OnComponentError get triggered.
archive.zip_20160822-0440.zip
Moderator

Re: tFileUnarchive - How to know if the zip is invalid or has no entries?

Hi,
The attachment you provided is not avaliable on talend forum. Could you please take a look at it?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.

Re: tFileUnarchive - How to know if the zip is invalid or has no entries?

Hi,
The zip may have been blocked by my firewall.  It doesn't matter, you can use any file that is not a zip file e.g. Take a jpg and rename it .zip to obtain an invalid zip file.  When you try to unzip it with the tFileUnarchive component you will get the behavior described in my previous post i.e. OnComponentError does not get triggered.
Best,
François
Seven Stars

Re: tFileUnarchive - How to know if the zip is invalid or has no entries?

Hi Francois,

 

I don't think the tFileUnarchive component, as standard, will allow you to do what you want. The only semi-sensible solution I could come up with, was to enable the "Use archive file name as root directory" option, then once the component has unzipped the archive, successfully or not, is to then check the number of files in the resulting sub-directory. If this is 0, then the archive was corrupt/unzippable.

 

Thanks

 

David

Regards

David

Don't forget to give Kudos when an answer is helpful or the solution.