0
# Third-Party Type Definitions
1
2
@react-native-community/cli-types includes type definitions for third-party modules used within the React Native CLI ecosystem. These are not directly exported from the package but are available when the package is installed.
3
4
## Capabilities
5
6
### Node Stream Zip Types
7
8
Type definitions for the 'node-stream-zip' module, providing TypeScript support for zip file operations within React Native CLI tools.
9
10
**Note:** These types are provided as module augmentation (`declare module 'node-stream-zip'`) and become available automatically when @react-native-community/cli-types is installed.
11
12
```typescript { .api }
13
/**
14
* Configuration options for StreamZip instances
15
*/
16
interface StreamZipOptions {
17
/** File path to read */
18
file: string;
19
/** Whether to store entries for random access (default: true) */
20
storeEntries?: boolean;
21
/** Skip entry name validation for malicious paths (default: false) */
22
skipEntryNameValidation?: boolean;
23
/** Chunk size for reading (default: automatic) */
24
chunkSize?: number;
25
}
26
27
/**
28
* Represents an entry within a zip archive
29
*/
30
class ZipEntry {
31
/** Entry name/path within the archive */
32
name: string;
33
/** Whether this entry is a directory */
34
isDirectory: boolean;
35
/** Whether this entry is a file */
36
isFile: boolean;
37
/** Comment associated with this entry */
38
comment: string;
39
/** Uncompressed size of the entry */
40
size: number;
41
}
42
43
/**
44
* Main class for reading zip archives
45
*/
46
class StreamZip {
47
/** Create new StreamZip instance */
48
constructor(config: StreamZipOptions);
49
50
/** Register event handler for when zip is ready to use */
51
on(event: 'ready', handler: () => void): void;
52
53
/** Get specific entry by name */
54
entry(entry: string): ZipEntry;
55
56
/** Get all entries in the archive */
57
entries(): ZipEntry[];
58
59
/** Total number of entries in the archive */
60
entriesCount: number;
61
62
/** Get readable stream for entry content */
63
stream(
64
entry: string,
65
callback: (err: any | null, stream?: Stream) => void,
66
): void;
67
68
/** Synchronously read entry data as buffer */
69
entryDataSync(entry: string): Buffer;
70
71
/** Open entry for reading */
72
openEntry(
73
entry: string,
74
callback: (err: any | null, entry?: ZipEntry) => void,
75
sync: boolean,
76
): void;
77
78
/** Extract entry or entire archive to filesystem */
79
extract(
80
entry: string | null,
81
outPath: string,
82
callback: (err?: any) => void,
83
): void;
84
85
/** Close the zip archive */
86
close(callback?: (err?: any) => void): void;
87
}
88
```
89
90
**Usage Examples:**
91
92
```typescript
93
// These types are available after installing @react-native-community/cli-types
94
import StreamZip from 'node-stream-zip';
95
import { Stream } from 'stream';
96
97
// Create zip reader
98
const zip = new StreamZip({
99
file: './archive.zip',
100
storeEntries: true
101
});
102
103
// Wait for zip to be ready
104
zip.on('ready', () => {
105
console.log(`Entries: ${zip.entriesCount}`);
106
107
// List all entries
108
const entries = zip.entries();
109
for (const entry of entries) {
110
console.log(`${entry.name}: ${entry.size} bytes`);
111
}
112
113
// Extract specific file
114
zip.extract('path/to/file.txt', './extracted/', (err) => {
115
if (err) throw err;
116
console.log('File extracted');
117
zip.close();
118
});
119
});
120
121
// Extract entire archive
122
zip.extract(null, './extracted/', (err) => {
123
if (err) throw err;
124
console.log('Archive extracted');
125
zip.close();
126
});
127
128
// Read file data synchronously (after 'ready' event)
129
zip.on('ready', () => {
130
const data = zip.entryDataSync('config.json');
131
const config = JSON.parse(data.toString());
132
console.log('Config:', config);
133
zip.close();
134
});
135
```
136
137
## Integration with React Native CLI
138
139
These zip utilities are used internally by React Native CLI for:
140
141
- Extracting project templates
142
- Processing bundled assets
143
- Handling compressed dependencies
144
- Archive-based project scaffolding
145
146
While not directly exported from @react-native-community/cli-types, these types ensure type safety when CLI tools work with zip archives.