cisv 0.0.19 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/benchmark/benchmark.js +3 -15
- package/cisv/cisv_parser.c +0 -2
- package/cisv/cisv_writer.c +0 -3
- package/package.json +1 -1
- package/cisv/test/typescript.test.ts +0 -43
- package/cisv/win_getopt.h +0 -100
- package/cisv/win_sys_time.h +0 -50
package/benchmark/benchmark.js
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// from calling benchmark from ./ root
|
|
6
|
-
cisvParser = require('../build/Release/cisv');
|
|
7
|
-
} catch (error1) {
|
|
8
|
-
try {
|
|
9
|
-
// from calling on npm publish ../pkg/
|
|
10
|
-
cisvParser = require('../../build/Release/cisv');
|
|
11
|
-
} catch (error2) {
|
|
12
|
-
// Handle the error if both attempts fail
|
|
13
|
-
console.error("Failed to load module from either relative path:", error1, error2);
|
|
14
|
-
throw new Error("cisv module could not be found in '../build/Release' or '../../build/Release'");
|
|
15
|
-
}
|
|
16
|
-
}
|
|
2
|
+
// direct node ./benchmark/benchmark.js
|
|
3
|
+
// means you have to call from :../build/Release/cisv
|
|
4
|
+
const { cisvParser } = require('../../build/Release/cisv');
|
|
17
5
|
const { parse: csvParseSync } = require('csv-parse/sync');
|
|
18
6
|
const { parse: csvParseStream } = require('csv-parse');
|
|
19
7
|
const Papa = require('papaparse');
|
package/cisv/cisv_parser.c
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
#include <stdio.h>
|
|
3
3
|
#include <stdlib.h>
|
|
4
4
|
#include <string.h>
|
|
5
|
-
#include "win_getopt.h"
|
|
6
5
|
#include <sys/stat.h>
|
|
7
6
|
#include <errno.h>
|
|
8
7
|
#include <time.h>
|
|
@@ -12,7 +11,6 @@
|
|
|
12
11
|
#include <unistd.h>
|
|
13
12
|
#include <getopt.h>
|
|
14
13
|
#include <sys/time.h>
|
|
15
|
-
#include "./cisv_simd.h"
|
|
16
14
|
#include "cisv_parser.h"
|
|
17
15
|
|
|
18
16
|
// #define RINGBUF_SIZE (1 << 20) // 1 MiB (we may adjust according to needs)
|
package/cisv/cisv_writer.c
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
#define _GNU_SOURCE
|
|
2
2
|
#include "cisv_writer.h"
|
|
3
|
-
#include "cisv_simd.h"
|
|
4
3
|
#include <stdlib.h>
|
|
5
4
|
#include <string.h>
|
|
6
5
|
#include <stdio.h>
|
|
7
|
-
#include <errno.h>
|
|
8
|
-
#include <ctype.h>
|
|
9
6
|
|
|
10
7
|
#define DEFAULT_BUFFER_SIZE (1 << 20) // 1MB
|
|
11
8
|
#define MIN_BUFFER_SIZE (1 << 16) // 64KB
|
package/package.json
CHANGED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { strict as assert } from 'assert';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
import { cisvParser } from '../index';
|
|
5
|
-
|
|
6
|
-
describe('TypeScript Integration', () => {
|
|
7
|
-
const testFile = path.join(__dirname, 'fixtures', 'typescript.csv');
|
|
8
|
-
|
|
9
|
-
before(() => {
|
|
10
|
-
fs.writeFileSync(testFile,
|
|
11
|
-
'id,name\n1,Test\n2,"Quoted,Name"');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should work with TypeScript types', () => {
|
|
15
|
-
const parser = new cisvParser();
|
|
16
|
-
const rows = parser.parseSync(testFile);
|
|
17
|
-
|
|
18
|
-
assert.strictEqual(rows.length, 2);
|
|
19
|
-
assert.deepStrictEqual(rows[0], ['1', 'Test']);
|
|
20
|
-
assert.deepStrictEqual(rows[1], ['2', 'Quoted,Name']);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should type check streaming API', async () => {
|
|
24
|
-
const parser = new cisvParser();
|
|
25
|
-
const stream = fs.createReadStream(testFile);
|
|
26
|
-
|
|
27
|
-
await new Promise<void>((resolve) => {
|
|
28
|
-
stream.on('data', (chunk: Buffer | string) => {
|
|
29
|
-
if (typeof chunk === 'string') {
|
|
30
|
-
parser.write(Buffer.from(chunk));
|
|
31
|
-
} else {
|
|
32
|
-
parser.write(chunk);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
stream.on('end', () => {
|
|
36
|
-
parser.end();
|
|
37
|
-
const rows = parser.getRows();
|
|
38
|
-
assert.strictEqual(rows.length, 2);
|
|
39
|
-
resolve();
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
package/cisv/win_getopt.h
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
#ifdef _WIN32
|
|
2
|
-
#include <windows.h>
|
|
3
|
-
|
|
4
|
-
#ifndef WIN_GETOPT_H
|
|
5
|
-
#define WIN_GETOPT_H
|
|
6
|
-
|
|
7
|
-
#include <string.h>
|
|
8
|
-
#include <stdio.h>
|
|
9
|
-
|
|
10
|
-
// Global variables
|
|
11
|
-
char* optarg = NULL; // Current option argument
|
|
12
|
-
int optind = 1; // Index of next argument to process
|
|
13
|
-
int opterr = 1; // Enable error messages (default: 1)
|
|
14
|
-
int optopt = 0; // Current option character
|
|
15
|
-
|
|
16
|
-
// Reset getopt internal state
|
|
17
|
-
void win_getopt_reset() {
|
|
18
|
-
optarg = NULL;
|
|
19
|
-
optind = 1;
|
|
20
|
-
opterr = 1;
|
|
21
|
-
optopt = 0;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
int getopt(int argc, char* const argv[], const char* optstring) {
|
|
25
|
-
static int optpos = 1; // Position within current argument
|
|
26
|
-
const char* colon = strchr(optstring, ':');
|
|
27
|
-
|
|
28
|
-
// Reset for new scan
|
|
29
|
-
optarg = NULL;
|
|
30
|
-
|
|
31
|
-
// Argument boundary checks
|
|
32
|
-
if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') {
|
|
33
|
-
return -1;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Handle "--" end of options
|
|
37
|
-
if (strcmp(argv[optind], "--") == 0) {
|
|
38
|
-
optind++;
|
|
39
|
-
return -1;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Get current option character
|
|
43
|
-
optopt = argv[optind][optpos++];
|
|
44
|
-
|
|
45
|
-
// Find option in optstring
|
|
46
|
-
char* optptr = strchr(optstring, optopt);
|
|
47
|
-
|
|
48
|
-
// Unknown option
|
|
49
|
-
if (!optptr) {
|
|
50
|
-
if (opterr && *optstring != ':')
|
|
51
|
-
fprintf(stderr, "%s: invalid option -- '%c'\n", argv[0], optopt);
|
|
52
|
-
return '?';
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Handle required argument
|
|
56
|
-
if (optptr[1] == ':') {
|
|
57
|
-
// Argument in current token
|
|
58
|
-
if (argv[optind][optpos] != '\0') {
|
|
59
|
-
optarg = &argv[optind][optpos];
|
|
60
|
-
optpos = 1;
|
|
61
|
-
optind++;
|
|
62
|
-
}
|
|
63
|
-
// Argument in next token
|
|
64
|
-
else if (argc > optind + 1) {
|
|
65
|
-
optarg = argv[optind + 1];
|
|
66
|
-
optind += 2;
|
|
67
|
-
optpos = 1;
|
|
68
|
-
}
|
|
69
|
-
// Missing argument
|
|
70
|
-
else {
|
|
71
|
-
if (opterr && *optstring != ':') {
|
|
72
|
-
fprintf(stderr, "%s: option requires an argument -- '%c'\n",
|
|
73
|
-
argv[0], optopt);
|
|
74
|
-
}
|
|
75
|
-
optpos = 1;
|
|
76
|
-
optind++;
|
|
77
|
-
return (colon && colon[1] == ':') ? ':' : '?';
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// No argument required
|
|
81
|
-
else {
|
|
82
|
-
if (argv[optind][optpos] == '\0') {
|
|
83
|
-
optpos = 1;
|
|
84
|
-
optind++;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return optopt;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
#endif // WIN_GETOPT_H
|
|
92
|
-
#elif defined(__linux__) || defined(__APPLE__)
|
|
93
|
-
#include <sys/mman.h>
|
|
94
|
-
#include <fcntl.h>
|
|
95
|
-
#include <unistd.h>
|
|
96
|
-
#include <getopt.h>
|
|
97
|
-
#include <sys/time.h>
|
|
98
|
-
#else
|
|
99
|
-
#error "Unsupported platform"
|
|
100
|
-
#endif
|
package/cisv/win_sys_time.h
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
#ifndef WIN_SYS_TIME_H
|
|
2
|
-
#define WIN_SYS_TIME_H
|
|
3
|
-
|
|
4
|
-
#ifdef _WIN32
|
|
5
|
-
#include <windows.h>
|
|
6
|
-
#include <stdint.h>
|
|
7
|
-
|
|
8
|
-
// Define timezone structure (dummy implementation)
|
|
9
|
-
struct timezone {
|
|
10
|
-
int tz_minuteswest; // minutes west of Greenwich
|
|
11
|
-
int tz_dsttime; // type of DST correction
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
// Get current time of day (Windows implementation)
|
|
15
|
-
static inline int gettimeofday(struct timeval* tv, struct timezone* tz) {
|
|
16
|
-
if (tv) {
|
|
17
|
-
FILETIME ft;
|
|
18
|
-
uint64_t tmpres = 0;
|
|
19
|
-
|
|
20
|
-
// Get current time as file time
|
|
21
|
-
GetSystemTimeAsFileTime(&ft);
|
|
22
|
-
|
|
23
|
-
// Convert to 64-bit integer
|
|
24
|
-
tmpres |= ft.dwHighDateTime;
|
|
25
|
-
tmpres <<= 32;
|
|
26
|
-
tmpres |= ft.dwLowDateTime;
|
|
27
|
-
|
|
28
|
-
// Convert to microseconds (1601-01-01 to 1970-01-01 is 11644473600 seconds)
|
|
29
|
-
tmpres /= 10; // Convert to microseconds
|
|
30
|
-
tmpres -= 11644473600000000ULL; // Offset to Unix epoch
|
|
31
|
-
|
|
32
|
-
tv->tv_sec = (long)(tmpres / 1000000UL);
|
|
33
|
-
tv->tv_usec = (long)(tmpres % 1000000UL);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// We don't support timezone on Windows
|
|
37
|
-
if (tz) {
|
|
38
|
-
tz->tz_minuteswest = 0;
|
|
39
|
-
tz->tz_dsttime = 0;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return 0;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
#else
|
|
46
|
-
// On non-Windows platforms, use the standard header
|
|
47
|
-
#include <sys/time.h>
|
|
48
|
-
#endif // _WIN32
|
|
49
|
-
|
|
50
|
-
#endif // WIN_SYS_TIME_H
|