-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install prebuilt rules package using stream-based approach
- Loading branch information
Showing
38 changed files
with
680 additions
and
81 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
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
83 changes: 83 additions & 0 deletions
83
x-pack/plugins/fleet/server/services/epm/archive/archive_iterator.ts
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { AssetsMap, ArchiveIterator, ArchiveEntry } from '../../../../common/types'; | ||
|
||
import { traverseArchiveEntries } from '.'; | ||
|
||
/** | ||
* Creates an iterator for traversing and extracting paths from an archive | ||
* buffer. This iterator is intended to be used for memory efficient traversal | ||
* of archive contents without extracting the entire archive into memory. | ||
* | ||
* @param archiveBuffer - The buffer containing the archive data. | ||
* @param contentType - The content type of the archive (e.g., | ||
* 'application/zip'). | ||
* @returns ArchiveIterator instance. | ||
* | ||
*/ | ||
export const createArchiveIterator = ( | ||
archiveBuffer: Buffer, | ||
contentType: string | ||
): ArchiveIterator => { | ||
const paths: string[] = []; | ||
|
||
const traverseEntries = async ( | ||
onEntry: (entry: ArchiveEntry) => Promise<void> | ||
): Promise<void> => { | ||
await traverseArchiveEntries(archiveBuffer, contentType, async (entry) => { | ||
await onEntry(entry); | ||
}); | ||
}; | ||
|
||
const getPaths = async (): Promise<string[]> => { | ||
if (paths.length) { | ||
return paths; | ||
} | ||
|
||
await traverseEntries(async (entry) => { | ||
paths.push(entry.path); | ||
}); | ||
|
||
return paths; | ||
}; | ||
|
||
return { | ||
traverseEntries, | ||
getPaths, | ||
}; | ||
}; | ||
|
||
/** | ||
* Creates an archive iterator from the assetsMap. This is a stop-gap solution | ||
* to provide a uniform interface for traversing assets while assetsMap is still | ||
* in use. It works with a map of assets loaded into memory and is not intended | ||
* for use with large archives. | ||
* | ||
* @param assetsMap - A map where the keys are asset paths and the values are | ||
* asset buffers. | ||
* @returns ArchiveIterator instance. | ||
* | ||
*/ | ||
export const createArchiveIteratorFromMap = (assetsMap: AssetsMap): ArchiveIterator => { | ||
const traverseEntries = async ( | ||
onEntry: (entry: ArchiveEntry) => Promise<void> | ||
): Promise<void> => { | ||
for (const [path, buffer] of assetsMap) { | ||
await onEntry({ path, buffer }); | ||
} | ||
}; | ||
|
||
const getPaths = async (): Promise<string[]> => { | ||
return [...assetsMap.keys()]; | ||
}; | ||
|
||
return { | ||
traverseEntries, | ||
getPaths, | ||
}; | ||
}; |
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
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
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
Oops, something went wrong.