-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fixed up header type mappings
- Loading branch information
1 parent
f10e844
commit d706025
Showing
3 changed files
with
33 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
import type { Stats } from 'fs'; | ||
|
||
// FIXME: Using 0s and 5s for files and directories isn't a good way to handle | ||
// this. I need to make it simpler so that I can assign and test using strings. | ||
// A potential solution is enums, but they don't work with types, so it's a bit | ||
// weird. | ||
type TarFile = '0'; | ||
const TarTypes = { | ||
FILE: '0', | ||
DIRECTORY: '5', | ||
} as const; | ||
|
||
type TarDirectory = '5'; | ||
|
||
type TarType = TarFile | TarDirectory; | ||
type TarType = (typeof TarTypes)[keyof typeof TarTypes]; | ||
|
||
type DirectoryContent = { | ||
path: string; | ||
stat: Stats; | ||
type: TarType; | ||
}; | ||
|
||
export type { TarFile, TarDirectory, TarType, DirectoryContent }; | ||
export type { TarType, DirectoryContent }; | ||
export { TarTypes }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
import { writeArchive } from '@/Generator'; | ||
import fs from 'fs'; | ||
import { createTar } from '@/Generator'; | ||
|
||
// TODO: actually write tests | ||
describe('index', () => { | ||
test.skip('test', async () => { | ||
await expect( | ||
writeArchive('/home/aryanj/Downloads', '/home/aryanj/archive.tar'), | ||
).toResolve(); | ||
test('test', async () => { | ||
if (process.env['CI'] != null) { | ||
// Skip this test if on CI | ||
expect(true).toEqual(true); | ||
} else { | ||
// Otherwise, run the test which creates a test archive | ||
const writeArchive = async (inputFile: string, outputFile: string) => { | ||
const fileHandle = await fs.promises.open(outputFile, 'w+'); | ||
for await (const chunk of createTar(inputFile)) { | ||
await fileHandle.write(chunk); | ||
} | ||
await fileHandle.close(); | ||
}; | ||
await expect( | ||
writeArchive('/home/aryanj/Downloads', '/home/aryanj/archive.tar'), | ||
).toResolve(); | ||
} | ||
}, 60000); | ||
}); |