Skip to content

Instantly share code, notes, and snippets.

@tswaters
Created November 29, 2015 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tswaters/c3f9394ccde46a480217 to your computer and use it in GitHub Desktop.
Save tswaters/c3f9394ccde46a480217 to your computer and use it in GitHub Desktop.
function transformAttributes (stats) {
attrs = parseInt(attrs, 8);
var others = attrs & 7;
var user = attrs >> 3 & 7;
var owner = attrs >> 6 & 7;
return [
owner & 4 ? 'r' : '-',
owner & 2 ? 'w' : '-',
owner & 1 ? 'x' : '-',
user & 4 ? 'r' : '-',
user & 2 ? 'w' : '-',
user & 1 ? 'x' : '-',
others & 4 ? 'r' : '-',
others & 2 ? 'w' : '-',
others & 1 ? 'x' : '-',
].join('');
}
transformAttributes('000'); // ---------
transformAttributes('755'); // rwxr-xr-x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment