Month: September 2021

Reading binary files: Use LineTerminator=NONE

I was reading binary files and forgot to set the LineTerminator parameter. It also confused me quite a lot, as the file stopped at byte value 37 and I am used to LineFeed being byte value 10.

But this i IBM i series and 37 is LineFeed… So I should have used:

Use Builtin(STM_FILE_OPEN) With_Args(#IZFILE 'READ BINARY LineTerminator=NONE NoTrim') To_Get(#FILENO #RETNCODE)

The fix for legacy WAM and Lansa v.14.2+

I didn’t post my solution to my problem in Lansa v.15 related to the style attribute in WAMs. I’ll correct that now:

Due to CSP any “style” attribute in the WAM source is moved to a “data-style” attribute, and then one of the new standard scripts move it back, client-side. Unfortunately, if you have a legacy solution you probably can’t use the new standard scripts.

The solution is to just add this simple javascript to your pages, preferably in a script file that is loaded on all pages:

document.querySelectorAll('[data-style]').forEach((elem) => {
  elem.style.cssText = (elem.style.cssText? (elem.style.cssText.match(/;\s*$/)? elem.style.cssText + elem.dataset.style : elem.style.cssText + "; " + elem.dataset.style) : elem.dataset.style);
  elem.removeAttribute('data-style');
});

It finds all DOM elements with a “data-style” attribute, adds the value from that to the “style” attribute of the element, and removes the “data-style” attribute. The reason why I don’t just set the cssText property to the value but potentially add the value, is that any javascript that might have run before might have set some style attributes already.

This will need to be adapted if you overwrite some styles with your current javascript.