diff --git a/README.md b/README.md index a75ccc8..3635e81 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,30 @@ # FastExcel -> This project using [Neon](https://neon-bindings.com) as a binding to Rust to execute fast and efficient memory usage for generating XLSX document. +> This project need Rust to be installed, check here for [Rust installation instruction](https://www.rust-lang.org/tools/install) -> Check here for [Rust installation instruction](https://www.rust-lang.org/tools/install) +> This project using [Rust](https://www.rust-lang.org) and [Neon](https://neon-bindings.com) as a binding to Rust to execute fast and efficient memory usage for generating XLSX document from NodeJs. + +> This project cannot be executed via NVM based NodeJs, you should deactivate (via `nvm deactivate`) and use a normal version installation of NodeJs. + +Writing a large amount of data into Excel file is not a trivial task when you have a limited memory (RAM) allocated. Especially when working at a small node on the server. This library is created to solve that problem, using the efficiency of Rust while generating XLSX from CSV. ### Installation + npm i -D cargo-cp-artifact + npm i fastexcel - npm i -D cargo-cp-artifact +### How it works -### Example +1. Generate the CSV +2. Convert the CSV to XLSX -``` -// index.js +The CSV generation is happen on the NodeJs side, and converting XLSX file is on Rust side (via Neon) + +### Example Usage + +```js +// dummy-excel.js const path = require('path'); const { CsvFileWriter, Converter } = require("fastexcel"); @@ -25,14 +36,14 @@ const main = async () => { console.log('dst', dst); const cols = []; - const totalCols = 200; + const totalCols = 200; // 200 columns for (let i = 0; i < totalCols; i++) { cols.push('Col ' + (i+1)); } const writer = new CsvFileWriter(src, cols); - const totalRows = 1000000; // 1jt rows + const totalRows = 1_000_000; // 1 million rows for (let i = 0; i < totalRows; i++) { let row = []; diff --git a/package-lock.json b/package-lock.json index 7161614..9453a34 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "fastexcel", - "version": "0.1.3", + "version": "0.1.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "fastexcel", - "version": "0.1.3", + "version": "0.1.4", "hasInstallScript": true, "license": "MIT", "devDependencies": { diff --git a/package.json b/package.json index 891a478..9a7293f 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,12 @@ { "name": "fastexcel", - "version": "0.1.3", + "version": "0.1.4", "description": "Fast and efficient large excel file writer", "main": "dist/index.js", + "repository": { + "type": "git", + "url": "git+https://github.com/slaveofcode/fastexcel.git" + }, "scripts": { "build": "cargo-cp-artifact -nc index.node -- cargo build --message-format=json-render-diagnostics", "build-debug": "npm run build --", @@ -22,5 +26,6 @@ "writer", "streaming", "office" - ] + ], + "homepage": "https://github.com/slaveofcode/fastexcel#readme" } diff --git a/src/lib.rs b/src/lib.rs index 928650c..08b7462 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -use std::{fs::File, error::Error, io::{Read, BufReader, BufRead, Write}, fmt::Display}; +use std::{fs::File, io::{BufReader, BufRead, Write}, fmt::Display}; use neon::{prelude::*}; use simple_xlsx_writer::{WorkBook, Row as XLSRow, Cell}; @@ -11,25 +11,6 @@ impl<'a> Display for Row<'a> { } } -#[allow(dead_code)] -fn read_file_buffer(filepath: String) -> Result<(), Box> { - const BUFFER_LEN: usize = 512; - let mut buffer = [0u8; BUFFER_LEN]; - let mut file = File::open(filepath)?; - - loop { - let read_count = file.read(&mut buffer)?; - let buff = &buffer[..read_count]; - let line = String::from_utf8_lossy(buff); - println!("line: {}", line); - - if read_count != BUFFER_LEN { - break; - } - } - Ok(()) -} - fn read_file_liner(filepath: String, fn_operation: &mut F) -> Result<(), std::io::Error> where F: FnMut(&mut Row) -> Result<(), std::io::Error> {