Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
prakashsvmx committed May 28, 2024
1 parent 0127e7c commit 7e2d777
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
43 changes: 10 additions & 33 deletions examples/compose-object-test-example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,23 @@ import * as Minio from 'minio'
import splitFile from 'split-file'

const s3Client = new Minio.Client({
endPoint: 'localhost',
accessKey: 'minio',
secretKey: 'minio123',
useSSL: false,
port: 22000,
//partSize: 5 * 1024 * 1024
endPoint: 's3.amazonaws.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY',
})

const bucketName = 'my-bucketname'
const composedObjName = 'my-objectname'

const oneMB = 1024 * 1024

// Create a bucket prior to running: mc mb local/source-bucket
const sampleRunComposeObject = async () => {
const tmpDir = os.tmpdir()

const bucketName = 'source-bucket'
// generate 100 MB buffer and write to a file.
const local100mbFileToBeSplitAndComposed = Buffer.alloc(100 * oneMB, 0)

const composedObjName = '_100-mb-file-to-test-compose'
const tmpSubDir = `${tmpDir}/compose`
const fileToSplit = `${tmpSubDir}/${composedObjName}`
const partObjNameList = []
Expand Down Expand Up @@ -87,33 +85,12 @@ const sampleRunComposeObject = async () => {
console.log(result)
console.log('Composed to a single file: ', composedObjName)
} catch (err) {
console.log('Composed to a single file: ', composedObjName)

/** Begin Clean up ***/
// To verify that the parts are uploaded properly, comment the below code blocks and verify
const sourcePartObjList = partObjNameList.map((partObjName) => {
console.log('Error in compose object : ', err.message)
} finally {
console.log('Remove source parts: ')
partObjNameList.map((partObjName) => {
return s3Client.removeObject(bucketName, partObjName)
})

Promise.all(sourcePartObjList)
.then(() => {
console.log('Removed source parts: ')

// Uncomment to remove the composed object itself. commented for verification.
/*
s3Client.removeObject(bucketName, composedObjName).then(()=>{
console.log("Clean up: Removed the composed Object ")
}).catch(()=>{
console.log("Error removing composed object", er)
})
*/
})
.catch((er) => {
console.log('Error removing parts used in composing', er)
})

/** End Clean up **/

// Clean up generated parts locally
fs.rmSync(tmpSubDir, { recursive: true, force: true })
console.log('Clean up temp parts directory : ')
Expand Down
5 changes: 3 additions & 2 deletions examples/compose-object.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const s3Client = new Minio.Client({
secretKey: 'YOUR-SECRETACCESSKEY',
})

const bucketName = 'source-bucket'
const bucketName = 'my-bucketname'
const objectName = 'my-objectname'

const sourceList = [
new Minio.CopySourceOptions({
Expand All @@ -51,7 +52,7 @@ const sourceList = [

const destOption = new Minio.CopyDestinationOptions({
Bucket: bucketName,
Object: 'object-name',
Object: objectName,
/** Other possible options */
/* Encryption:{
type:Helpers.ENCRYPTION_TYPES.KMS,
Expand Down

0 comments on commit 7e2d777

Please sign in to comment.