Skip to content

Commit

Permalink
Allow to declare binary data on js:GlobRead
Browse files Browse the repository at this point in the history
  • Loading branch information
julianrojas87 committed Feb 1, 2024
1 parent c3ba4ed commit bcd0a80
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 9 additions & 0 deletions processors.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ js:GlobRead a js:JsProcess;
a fnom:PositionParameterMapping ;
fnom:functionParameter "closeOnEnd";
fnom:implementationParameterPosition "3"^^xsd:integer
], [
a fnom:PositionParameterMapping ;
fnom:functionParameter "binary";
fnom:implementationParameterPosition "4"^^xsd:integer
]
].

Expand Down Expand Up @@ -56,6 +60,11 @@ js:GlobRead a js:JsProcess;
sh:name "closeOnEnd";
sh:datatype xsd:boolean;
sh:maxCount 1
], [
sh:path js:binary;
sh:name "binary";
sh:datatype xsd:boolean;
sh:maxCount 1
].

js:FolderRead a js:JsProcess;
Expand Down
5 changes: 3 additions & 2 deletions src/FileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ export async function globRead(
globPattern: string,
writer: Writer<string | Buffer>,
wait: number = 0,
closeOnEnd: boolean = true
closeOnEnd: boolean = true,
binary: boolean = false
) {
const jsfiles = await glob(globPattern, {});
const files = await Promise.all(
jsfiles.map((x) => {
console.log(`[globRead] reading file ${x} (from glob pattern ${globPattern})`);
return readFile(x)
return readFile(x, binary ? {} : { encoding: "utf8" });
}),
);

Expand Down
8 changes: 5 additions & 3 deletions tests/Processors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ describe("File Utils tests", () => {
js:glob "./*";
js:output <jw>;
js:wait 0;
js:closeOnEnd true.
js:closeOnEnd true;
js:binary true.
`;

const source: Source = {
Expand All @@ -45,13 +46,14 @@ describe("File Utils tests", () => {

const argss = extractSteps(env, quads, config);
expect(argss.length).toBe(1);
expect(argss[0].length).toBe(4);
expect(argss[0].length).toBe(5);

const [[glob, output, wait, closeOnEnd]] = argss;
const [[glob, output, wait, closeOnEnd, binary]] = argss;
expect(glob).toBe("./*");
testWriter(output);
expect(wait).toBe(0);
expect(closeOnEnd).toBeTruthy();
expect(binary).toBeTruthy();

await checkProc(env.file, env.func);
});
Expand Down

0 comments on commit bcd0a80

Please sign in to comment.