How to validate a TAR file in Node.JS

Having a proper means of validating files is crucial if you are to avoid a tedious fate, especially when working with large file volumes. I know what you’re thinking, Node.JS is not ideal for setting up such a system, and it’s probably going to take hours to get it off the ground. Normally, that would be the case, but in this article I am going to show you a much easier means of getting the same result. By using an API with TAR validation capabilities, you can easily add this to your project without much effort at all.

With npm install, we shall import our client.

npm install cloudmersive-convert-api-client --save

Now we can call our function using this sample code here:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.ValidateDocumentApi();var inputFile = "/path/to/file"; // File | Input file to perform the operation on.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.validateDocumentTarValidation(inputFile, callback);

Now just feed it your TAR files and you will get back your results like this:

{
"DocumentIsValid": true,
"PasswordProtected": true,
"ErrorCount": 0,
"WarningCount": 0,
"ErrorsAndWarnings": [
{
"Description": "string",
"Path": "string",
"Uri": "string",
"IsError": true
}
]
}

Easy. This API contains many other useful functions, allowing you to validate other archive types as well as various document formats like DOCX and PPTX.

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.