21 lines
497 B
JavaScript
21 lines
497 B
JavaScript
import Tar from 'tar-js'; // converts a string to utf8 Uint8Array and returns it as a string-like
|
|
// object that `tar.append` accepts as path
|
|
|
|
function fixUnicodePath(path) {
|
|
const codes = new TextEncoder().encode(path);
|
|
return {
|
|
length: codes.length,
|
|
charCodeAt: index => codes[index]
|
|
};
|
|
}
|
|
|
|
export function makeTar(data) {
|
|
const tar = new Tar();
|
|
|
|
for (const entry of data) {
|
|
const path = fixUnicodePath(entry.path);
|
|
tar.append(path, entry.data);
|
|
}
|
|
|
|
return tar.out;
|
|
} |