8000 Add file name prefix handling + fix incorrect user + group handling by ofersadgat · Pull Request #39 · unjs/nanotar · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add file name prefix handling + fix incorrect user + group handling #39

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
36 changes: 26 additions & 10 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,33 @@ export function parseTar<
// No default
}

let user, group;
// Ustar indicator (offset: 257 - length: 6)
// Ignore

// Ustar version (offset: 263 - length: 2)
// Ignore

// File owner user (offset: 265 - length: 32)
const user = _readString(buffer, offset + 265, 32);

// File owner group (offset: 297 - length: 32)
const group = _readString(buffer, offset + 297, 32);
const ustar = _readString(buffer, offset + 257, 6);
if (ustar == 'ustar'){
// Ustar version (offset: 263 - length: 2)
// Ignore

// File owner user (offset: 265 - length: 32)
user = _readString(buffer, offset + 265, 32);

// File owner group (offset: 297 - length: 32)
group = _readString(buffer, offset + 297, 32);

// Filename prefix (offset: 345 - length: 155)
const prefix = _readString(buffer, offset + 345, 155);
if (prefix){
const prefixEndsWithSlash = prefix.endsWith('/');
const nameStartsWithSlash = name.startsWith('/');
if (prefixEndsWithSlash && nameStartsWithSlash){
name = prefix + name.substring(1);
} else if (prefixEndsWithSlash || nameStartsWithSlash){
name = prefix + name;
} else {
name = prefix + '/' + name;
}
}
}

// Group all file metadata
const meta: ParsedTarFileItemMeta = {
Expand Down
0