Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@imirfanul/csv-processor
Advanced tools
A Node.js package for processing large CSV files in chunks, designed for modular and flexible use with any database or data handling system.
A Node.js package for processing large CSV files in chunks, designed for modular and flexible use with any database or data handling system.
Install the package via npm:
npm install @imirfanul/csv-processor
First, import the necessary classes from the package:
import { CSVProcessor, CSVProcessorConfig, ChunkHandler } from '@imirfanul/csv-processor';
Configure the CSVProcessor with the desired chunk size and CSV file path:
const csvProcessorConfig: CSVProcessorConfig = {
chunkSize: 100000,
csvFilePath: 'path/to/your/large_file.csv',
};
const csvProcessor = new CSVProcessor(csvProcessorConfig);
Define a chunkHandler
function that processes each chunk of data. This can be customized to perform any operation, such as inserting data into a database.
Example with PostgreSQL:
import { Pool } from 'pg';
const dbConfig = {
user: 'username',
host: 'localhost',
database: 'your_database',
password: 'password',
port: 5432,
};
const pool = new Pool(dbConfig);
const chunkHandler: ChunkHandler = async (chunk) => {
const client = await pool.connect();
try {
const values = chunk.map(row => `(${Object.values(row).map(val => `'${val}'`).join(',')})`).join(',');
const columns = Object.keys(chunk[0]).map(col => `"${col}"`).join(',');
const query = `INSERT INTO your_table (${columns}) VALUES ${values}`;
await client.query(query);
console.log(`Inserted ${chunk.length} rows`);
} catch (error) {
console.error('Error inserting chunk:', error);
} finally {
client.release();
}
};
Call the processCSV
method with the chunkHandler
:
csvProcessor.processCSV(chunkHandler).then(() => {
console.log('CSV processing complete.');
}).catch(error => {
console.error('Error during CSV processing:', error);
});
Here is a full example combining all the pieces together:
import { CSVProcessor, CSVProcessorConfig, ChunkHandler } from 'your-package-name';
import { Pool } from 'pg';
const dbConfig = {
user: 'username',
host: 'localhost',
database: 'your_database',
password: 'password',
port: 5432,
};
const pool = new Pool(dbConfig);
const csvProcessorConfig: CSVProcessorConfig = {
chunkSize: 100000,
csvFilePath: 'path/to/your/large_file.csv',
};
const csvProcessor = new CSVProcessor(csvProcessorConfig);
const chunkHandler: ChunkHandler = async (chunk) => {
const client = await pool.connect();
try {
const values = chunk.map(row => `(${Object.values(row).map(val => `'${val}'`).join(',')})`).join(',');
const columns = Object.keys(chunk[0]).map(col => `"${col}"`).join(',');
const query = `INSERT INTO your_table (${columns}) VALUES ${values}`;
await client.query(query);
console.log(`Inserted ${chunk.length} rows`);
} catch (error) {
console.error('Error inserting chunk:', error);
} finally {
client.release();
}
};
csvProcessor.processCSV(chunkHandler).then(() => {
console.log('CSV processing complete.');
}).catch(error => {
console.error('Error during CSV processing:', error);
});
This package is licensed under the MIT License. See the LICENSE file for more information.
FAQs
A Node.js package for processing large CSV files in chunks, designed for modular and flexible use with any database or data handling system.
We found that @imirfanul/csv-processor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.