Skip to content

Commit 4340e27

Browse files
committed
Add ability to configure encoding
1 parent a928f82 commit 4340e27

File tree

5 files changed

+64
-16
lines changed

5 files changed

+64
-16
lines changed

api-extractor.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3+
"mainEntryPointFilePath": "<projectFolder>lib/index.d.ts",
4+
"bundledPackages": [],
5+
"compiler": {},
6+
"apiReport": {
7+
"enabled": false
8+
},
9+
"docModel": {
10+
"enabled": true,
11+
"apiJsonFilePath": "<projectFolder>/temp/<unscopedPackageName>.api.json"
12+
},
13+
"dtsRollup": {
14+
"enabled": true,
15+
"untrimmedFilePath": "<projectFolder>/temp/<unscopedPackageName>.d.ts"
16+
},
17+
"tsdocMetadata": {},
18+
"messages": {
19+
"compilerMessageReporting": {
20+
"default": {
21+
"logLevel": "none"
22+
}
23+
},
24+
"extractorMessageReporting": {
25+
"default": {
26+
"logLevel": "none"
27+
},
28+
"ae-forgotten-export": {
29+
"logLevel": "none"
30+
}
31+
},
32+
"tsdocMessageReporting": {
33+
"default": {
34+
"logLevel": "none"
35+
}
36+
}
37+
}
38+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"json-parser"
2727
],
2828
"scripts": {
29-
"build": "rm -rf ./lib && tsc && yarn ts-docflux",
29+
"build": "rm -rf ./lib && tsc",
3030
"watch": "yarn link && tsc --watch",
3131
"test": "cd ./benchmarks && yarn && yarn test"
3232
},
@@ -61,6 +61,6 @@
6161
"papaparse": "^5.2.0",
6262
"pretty-ms": "^7.0.1",
6363
"tmp": "^0.2.1",
64-
"ts-prime": "0.3.15"
64+
"ts-prime": "^1.0.0"
6565
}
6666
}

src/cache.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,28 @@ export function _cacheIter<T>(data: AnyIterable<T>, options: CacheIterOptions):
6565
const lockFile = resolve(options.cacheFolder, ".lock")
6666
if (existsSync(lockFile)) {
6767
options.logger?.info('Lock file exist. This usually means that iterator was not cached fully. Cache folder will be deleted and recreated with new iterator')
68-
rmdirSync(options.cacheFolder, { recursive: true })
68+
rmdirSync(options.cacheFolder)
6969
}
7070
if (!existsSync(metaFile)) {
7171
options.logger?.info('Meta file does not exists. Deleting cache folder...')
72-
rmdirSync(options.cacheFolder, { recursive: true })
72+
removeIfExists(options);
7373
}
7474

7575
if (existsSync(metaFile)) {
7676
const meta: { referenceId: string, createdAt: string, iteratableId: string, format: CacheIterOptions['nice'] } = await readJSON(metaFile)
7777
if (meta.referenceId !== referenceId) {
7878
options.logger?.info('Reference id changed. Deleting cache folder...')
79-
rmdirSync(options.cacheFolder, { recursive: true })
79+
removeIfExists(options);
8080
}
8181

8282
if (!P.equals(meta.format, options.nice)) {
8383
options.logger?.info('Cache format changed. Deleting cache folder...')
84-
rmdirSync(options.cacheFolder, { recursive: true })
84+
removeIfExists(options);
8585
}
8686

8787
if (!P.equals(meta.iteratableId, iteratableId)) {
8888
options.logger?.info('Source iterator structure changed. Deleting cache folder...')
89-
rmdirSync(options.cacheFolder, { recursive: true })
89+
removeIfExists(options);
9090
}
9191
}
9292

@@ -106,7 +106,7 @@ export function _cacheIter<T>(data: AnyIterable<T>, options: CacheIterOptions):
106106
const cache = getCache()
107107
if (cache) return cache
108108
if (existsSync(options.cacheFolder)) {
109-
rmdirSync(options.cacheFolder, { recursive: true })
109+
removeIfExists(options)
110110
}
111111
await ensureFile(lockFile)
112112

@@ -135,6 +135,12 @@ export function _cacheIter<T>(data: AnyIterable<T>, options: CacheIterOptions):
135135
})
136136
}
137137

138+
function removeIfExists(options: CacheIterOptions) {
139+
if (existsSync(options.cacheFolder)) {
140+
rmdirSync(options.cacheFolder);
141+
}
142+
}
143+
138144
/**
139145
* Cache iterator output to file.
140146
* Useful when we need develop complex iterator pipelines.

src/xml.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export interface XMLReadOptions extends ProgressReportOptions, FastXMLParser, Fi
8686
* <Person>...</Person>
8787
*/
8888
nodeName: string
89+
encoding?: "utf8" | "utf16le" | "ascii" | "base64" | "binary"
8990
}
9091
export interface FastXMLWriteOptions {
9192
/**
@@ -250,7 +251,7 @@ export function xmlRead<T>(options: XMLReadOptions): IX<T> {
250251
arrayMode: false, //"strict"
251252
}
252253
let count = 0
253-
const elMatch = new RegExp(`<${options.nodeName}( .*)?>`, 'gm')
254+
const elMatch = new RegExp(`<${options.nodeName}( ?.*)?>`, 'gm')
254255
async function* iter() {
255256
for await (const buffer of bufferRead({
256257
...options,
@@ -261,7 +262,10 @@ export function xmlRead<T>(options: XMLReadOptions): IX<T> {
261262
options.progress?.(q)
262263
}
263264
})) {
264-
const full = `${last}${buffer.toString()}`
265+
const full = `${last}${buffer.toString(options.encoding)}`
266+
if (!full.match(elMatch)) {
267+
throw new Error(`Failed to find node: ${options.nodeName}`)
268+
}
265269
const beef = full.replace(elMatch, `!@###@!<${options.nodeName}>`).split(`!@###@!`)
266270
last = beef.pop() || ''
267271
for (const qwe of beef) {
@@ -273,7 +277,7 @@ export function xmlRead<T>(options: XMLReadOptions): IX<T> {
273277
...options
274278

275279
})[options.nodeName]
276-
if (parsedResult == null) continue
280+
if (parsedResult == null) continue
277281
yield parsedResult
278282
count++
279283
}

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,16 +600,16 @@ ts-docflux@^0.0.13:
600600
xml-flow "^1.0.4"
601601
zod "^1.11.11"
602602

603-
ts-prime@0.3.15:
604-
version "0.3.15"
605-
resolved "https://registry.yarnpkg.com/ts-prime/-/ts-prime-0.3.15.tgz#75fc8777b6618ae3136a3d599d339f52617ad2ec"
606-
integrity sha512-ADiQE/4hGlzy/AkVCE+Vt5ETe8QOUSCbbrL9Vo9lGps/fUKIYykje9hLj/6Mbbcq684u872G3Ul7D84vM0+/xw==
607-
608603
ts-prime@^0.3.7:
609604
version "0.3.12"
610605
resolved "https://registry.yarnpkg.com/ts-prime/-/ts-prime-0.3.12.tgz#0b755d8dc366ecb49d4b337864b289d2e5c2161a"
611606
integrity sha512-HsaCT3zW5+HaSMXYVC7nC8fI7R2MqGOg6yvjmhY3OiMG5lETVDq1shmuL1/+t5jmHDI2XHDlR8UyH4aXFEKz8g==
612607

608+
ts-prime@^1.0.0:
609+
version "1.0.0"
610+
resolved "https://registry.yarnpkg.com/ts-prime/-/ts-prime-1.0.0.tgz#573f73e67f30478a0c3317da47cab9bf053d1056"
611+
integrity sha512-+vHlwnDWLaSDcLPBMBFjnSbbY/HZwg5eju9/pmNsGiXL6N/Gwd/d6w0PGCbnRm7j+mMISQrRUiVVvExTS6GJxA==
612+
613613
tslib@^1.9.3:
614614
version "1.14.1"
615615
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"

0 commit comments

Comments
 (0)