How to validate a RAR file in Node.JS

Cloudmersive
2 min readJun 29, 2020

--

File validation is the surest way to avoid being tortured by problematic files somewhere down the line. To set up this type of system for RAR archives in Node.JS, you would normally need a few hours and a whole heap of patience. You notice I said normally. That’s because today we are going to accomplish this validation without any of the hard work. In fact we will have you ready to go in less than 10 minutes.

This type of rapid results can be achieved via an API, whose client we will install as our first step.

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

And now we just need to call our function, like so:

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.validateDocumentRarValidation(inputFile, callback);

And if we run that with our input file, we will get back a response like this:

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

That’s it! Your RAR validation woes are now a thing of the past. This library also offers validation options for other types of files, including ZIP, DOCX, CSV, and many more.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet