Skip to content

Commit

Permalink
BREAKING(archive): move to single-export files (#2958)
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua authored Dec 4, 2022
1 parent b454363 commit 259d5a7
Showing 8 changed files with 881 additions and 736 deletions.
159 changes: 159 additions & 0 deletions archive/_common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.

import { PartialReadError } from "../io/buffer.ts";

export type Reader = Deno.Reader;
export type Seeker = Deno.Seeker;

export interface TarInfo {
fileMode?: number;
mtime?: number;
uid?: number;
gid?: number;
owner?: string;
group?: string;
type?: string;
}

export interface TarOptions extends TarInfo {
/**
* append file
*/
filePath?: string;

/**
* append any arbitrary content
*/
reader?: Reader;

/**
* size of the content to be appended
*/
contentSize?: number;
}

export interface TarMeta extends TarInfo {
fileName: string;
fileSize?: number;
}

export enum FileTypes {
"file" = 0,
"link" = 1,
"symlink" = 2,
"character-device" = 3,
"block-device" = 4,
"directory" = 5,
"fifo" = 6,
"contiguous-file" = 7,
}

export const recordSize = 512;

/*
struct posix_header { // byte offset
char name[100]; // 0
char mode[8]; // 100
char uid[8]; // 108
char gid[8]; // 116
char size[12]; // 124
char mtime[12]; // 136
char chksum[8]; // 148
char typeflag; // 156
char linkname[100]; // 157
char magic[6]; // 257
char version[2]; // 263
char uname[32]; // 265
char gname[32]; // 297
char devmajor[8]; // 329
char devminor[8]; // 337
char prefix[155]; // 345
// 500
};
*/

export const ustarStructure: Array<{ field: string; length: number }> = [
{
field: "fileName",
length: 100,
},
{
field: "fileMode",
length: 8,
},
{
field: "uid",
length: 8,
},
{
field: "gid",
length: 8,
},
{
field: "fileSize",
length: 12,
},
{
field: "mtime",
length: 12,
},
{
field: "checksum",
length: 8,
},
{
field: "type",
length: 1,
},
{
field: "linkName",
length: 100,
},
{
field: "ustar",
length: 8,
},
{
field: "owner",
length: 32,
},
{
field: "group",
length: 32,
},
{
field: "majorNumber",
length: 8,
},
{
field: "minorNumber",
length: 8,
},
{
field: "fileNamePrefix",
length: 155,
},
{
field: "padding",
length: 12,
},
];

export async function readBlock(
reader: Deno.Reader,
p: Uint8Array,
): Promise<number | null> {
let bytesRead = 0;
while (bytesRead < p.length) {
const rr = await reader.read(p.subarray(bytesRead));
if (rr === null) {
if (bytesRead === 0) {
return null;
} else {
throw new PartialReadError();
}
}
bytesRead += rr;
}
return bytesRead;
}
6 changes: 6 additions & 0 deletions archive/_test_common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { dirname, fromFileUrl, resolve } from "../path/mod.ts";

const moduleDir = dirname(fromFileUrl(import.meta.url));
export const testdataDir = resolve(moduleDir, "testdata");
export const filePath = resolve(testdataDir, "example.txt");
40 changes: 40 additions & 0 deletions archive/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.

/*!
* Ported and modified from: https://github.com/beatgammit/tar-js and
* licensed as:
*
* (The MIT License)
*
* Copyright (c) 2011 T. Jameson Little
* Copyright (c) 2019 Jun Kato
* Copyright (c) 2018-2022 the Deno authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

/**
* Provides a `Tar` and `Untar` classes for compressing and decompressing
* arbitrary data.
*
* @module
*/
/** @deprecated (will be removed after 0.169.0) TODO: export all once overlapping objects/types are removed */
export { Tar, type TarData, type TarDataWithSource } from "./tar.ts";
export * from "./untar.ts";
Loading

0 comments on commit 259d5a7

Please sign in to comment.