Skip to content

Commit

Permalink
Merge branch 'release/v0.1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
slaveofcode committed Dec 12, 2022
2 parents e409d95 + cf51a88 commit 5bc0370
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 32 deletions.
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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");

Expand All @@ -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 = [];

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 --",
Expand All @@ -22,5 +26,6 @@
"writer",
"streaming",
"office"
]
],
"homepage": "https://github.com/slaveofcode/fastexcel#readme"
}
21 changes: 1 addition & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -11,25 +11,6 @@ impl<'a> Display for Row<'a> {
}
}

#[allow(dead_code)]
fn read_file_buffer(filepath: String) -> Result<(), Box<dyn Error>> {
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<F>(filepath: String, fn_operation: &mut F) -> Result<(), std::io::Error>
where
F: FnMut(&mut Row) -> Result<(), std::io::Error> {
Expand Down

0 comments on commit 5bc0370

Please sign in to comment.