Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support QsysFs INB files for IBM i Notebooks #818

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ Thanks so much to everyone [who has contributed](https://github.com/halcyon-tech
* [@EddieSmith](https://github.com/EddieSmith)
* [@fathert](https://github.com/fathert)
* [@Teqed](https://github.com/Teqed)
* [@Wright4i](https://github.com/Wright4i)
8 changes: 4 additions & 4 deletions src/filesystems/qsys/complex.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ module.exports = class ComplexQsysFs {
*/
async readFile(uri) {
const connection = instance.getConnection();
const {asp, library, file, member} = connection.parserMemberPath(uri.path);
const {asp, library, file, member, extension} = connection.parserMemberPath(uri.path);

const memberContent = await contentApi.downloadMemberContentWithDates(asp, library, file, member);
const memberContent = await contentApi.downloadMemberContentWithDates(asp, library, file, member, extension);

return new Uint8Array(Buffer.from(memberContent, `utf8`));
}
Expand All @@ -40,9 +40,9 @@ module.exports = class ComplexQsysFs {
*/
writeFile(uri, content, options) {
const connection = instance.getConnection();
const {asp, library, file, member} = connection.parserMemberPath(uri.path);
const {asp, library, file, member, extension} = connection.parserMemberPath(uri.path);

return contentApi.uploadMemberContentWithDates(asp, library, file, member, content.toString(`utf8`));
return contentApi.uploadMemberContentWithDates(asp, library, file, member, extension, content.toString(`utf8`));
}

/**
Expand Down
28 changes: 24 additions & 4 deletions src/filesystems/qsys/complex/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ module.exports = class IBMiContent {
* @param {string} lib
* @param {string} spf
* @param {string} mbr
* @param {string} ext
*/
static async downloadMemberContentWithDates(asp, lib, spf, mbr) {
static async downloadMemberContentWithDates(asp, lib, spf, mbr, ext) {
const connection = instance.getConnection();
const content = instance.getContent();

lib = lib.toUpperCase();
spf = spf.toUpperCase();
mbr = mbr.toUpperCase();
ext = ext.toUpperCase();

const tempLib = connection.config.tempLibrary;
const alias = `${lib}_${spf}_${mbr.replace(/\./g, `_`)}`;
Expand Down Expand Up @@ -57,9 +59,10 @@ module.exports = class IBMiContent {
}

const sourceDates = rows.map(row => String(row.SRCDAT).padStart(6, `0`));
const joinChar = (ext===`INB`) ? `` : `\n`;
const body = rows
.map(row => row.SRCDTA)
.join(`\n`);
.join(joinChar);

allSourceDates[alias] = sourceDates;

Expand All @@ -73,9 +76,10 @@ module.exports = class IBMiContent {
* @param {string} lib
* @param {string} spf
* @param {string} mbr
* @param {string} ext
* @param {string} body
*/
static async uploadMemberContentWithDates(asp, lib, spf, mbr, body) {
static async uploadMemberContentWithDates(asp, lib, spf, mbr, ext, body) {
const connection = instance.getConnection();
const setccsid = connection.remoteFeatures.setccsid;

Expand All @@ -88,9 +92,25 @@ module.exports = class IBMiContent {
const tempRmt = connection.getTempRemote(lib + spf + mbr);
const tmpobj = await tmpFile();

const sourceData = body.split(`\n`);
let sourceData = body.split(`\n`);
const recordLength = recordLengths[alias] || DEFAULT_RECORD_LENGTH;

// Split JSON documents at record length. IBM i Notebooks support.
ext = ext.toUpperCase();
if (sourceData.length === 1 && ext === `INB`) {
let sourceJson = ``;
try {
sourceJson = JSON.parse(sourceData[0]);
} catch(e) {
// Invalid JSON string
}

if (sourceJson !== ``) {
const re = new RegExp(`.{1,${recordLength}}`,`g`);
sourceData = sourceData[0].match(re);
}
}

const decimalSequence = sourceData.length >= 10000;

let rows = [],
Expand Down