분산 파일 시스템 또는 스토리지 영역 네트워크와 함께 사용할 때 충돌을 방지하도록 설계된 파일 시스템 Blob Store.
github / npm에 출연 하고 업데이트를 보십시오 .
참고 : node.js v12 이상이 필요합니다.
npm install scalable-blob-store --save
const os = require ( 'os' ) ;
const ulid = require ( 'ulid' ) . ulid ; // You need a unique ID generator function
const BlobStore = require ( 'scalable-blob-store' ) ;
const options = {
blobStoreRoot : os . tmpdir ( ) + '/blobs' , // Change this!
idFunction : ulid ,
dirDepth : 4 ,
dirWidth : 1000 ,
} ;
// Creating the blobStore Object
const blobStore = new BlobStore ( options ) ;
const result = await blobStore . createWriteStream ( ) ;
console . dir ( result ) ;
// Logs the result object which contains the blobPath and writeStream.
// Use the writeStream to save your blob.
// Store the blobPath in your database.
//
// result object will be similar to this:
// {
// blobPath: "/01CTZRTWMAD153V20K26S4Y0BW/01CTZRTWMBZW4SPR4E5QGGJYSH/01CTZRTWMB3QXZK04SYFY8ZJVR/01CTZS3KJYFPRQ34S3T15Y798S",
// writeStream: [WriteStream]
// }
//
// In this example the full file path for the blob would be something like this:
// /tmp/blobs/01CTZRTWMAD153V20K26S4Y0BW/01CTZRTWMBZW4SPR4E5QGGJYSH/01CTZRTWMB3QXZK04SYFY8ZJVR/01CTZS3KJYFPRQ34S3T15Y798S
//
// This is based on the blobStoreRoot + blobPath.자세한 내용은 빠른 시작 예제 파일을 참조하십시오.
웹 응용 프로그램을 위해 사용자 파일 스토리지 또는 Blob Storage를 조사한 후 웹 개발자가 사용하는 가장 일반적인 솔루션은 클라우드 서비스 제공 업체를 사용하여 파일을 저장하는 것입니다. Amazon S3, Google Cloud Storage 또는 Azure Storage와 같은 제공 업체와 계정을 작성한 후 모든 응용 프로그램 파일과 블로브를 보관합니다.
나는 클라우드 스토리지의 가격을 조사하고 필요한 경우 확장 할 무료 로컬 버전을 원한다고 결정했습니다.
나는 Filestorage와 같은 여러 기존 솔루션을 살펴 보았지만 이러한 솔루션의 확장성에 불만이있었습니다. 대부분은 단일 서버 용으로 만 설계되었으며 분산 파일 시스템, Glusterfs와 같은 클러스터 파일 시스템 또는 스토리지 영역 네트워크가 백엔드 파일 시스템으로 사용 된 경우 쓰기 충돌을 일으 킵니다.
긴 자동차 여행에서 나는 내 블로브 보관 용액에 대해 생각하고 있었고 scalable-blob-store 만들었습니다.
분산 또는 복제 된 파일 시스템에서 확장 성을 달성하기 위해 scalable-blob-store 인덱스 파일 또는 기타 데이터베이스를 사용하여 디스크 또는 스토리지 시스템의 파일을 관리하지 않습니다. 대신 파일 시스템 자체는 파일 시스템 birthtime 속성 (디렉토리 생성 날짜)을 기반으로 최신 스토리지 경로를 찾는 데 사용됩니다.
최신 경로가 결정되면 디렉토리 내의 파일 수가 계산되어 구성된 값에 따라 유지됩니다. 이는 매우 많은 수의 파일이 단일 디렉토리 내에 저장 될 때 디스크 성능 문제를 방지하기위한 것입니다. 디렉토리의 항목 수가 너무 커지면 새로운 저장 경로가 결정됩니다.
루트 경로에서 파일을 관리하는 데 사용되는 데이터베이스가 없기 때문에 자신의 데이터베이스에 저장된 파일에 대한 반환 된 blobPath 값과 메타 데이터를 유지하는 것은 귀하에게 달려 있습니다.
scalable-blob-store 확장 가능하는 이유는 파일 시스템 내에서 디렉토리 및 파일의 이름을 지정하기 때문입니다. 디스크에 저장된 모든 디렉토리 및 파일은 사용자 정의 된 funciton을 기반으로 생성 된 고유 ID로 명명됩니다. Ulid, Cuid, UUID V4 또는 Mongodbs Objectids와 같은 고유 한 ID 생성기를 사용하여 몇 가지 이름을 지정할 수 있습니다. 더 많은 예를 들어 멋진 독특한 ID 저장소를 확인하십시오. 서버 또는 디스크 간의 디렉토리 병합은 파일 이름 충돌을 일으키지 않아야합니다.
복제 또는 클러스터 파일 시스템이 사용되는 경우 한 서버가 파일을 읽고 다른 서버가 동일한 파일을 제거하는 경우 발생할 수있는 유일한 충돌은 발생합니다. scalable-blob-store 이러한 갈등을 관리하려고 시도하지 않지만 예외가 발생합니다.
다음은 scalable-blob-store 에 의해 생성 된 디렉토리 구조의 예입니다.
CUID 디렉토리 및 파일 이름이 포함 된 예 :
b lobs c ij50xia200pzzph3we9r62bi // ← Directory File ↓
b lobs c ij50xia300q1zph3m4df4ypz . . c ij50xiae00qgzph3i0ms0l2wUUID 디렉토리 및 파일 이름의 예 :
b lobs 8 46a291f-9864-40bb-aefe-f29bdc73a761 // ← Directory File ↓
b lobs 8 46a291f-9864-40bb-aefe-f29bdc73a761 . . 8 b86b6fe-6166-424c-aed9-8faf1e62689e scalable-blob-store 구성 옵션을 지원하여 사용 된 디렉토리 및 파일 ID, 디렉토리 구조의 깊이 및 디렉토리의 폭에 대한 제어를 제공합니다. 기본 옵션은 디렉토리 구조 내에서 10 억 파일을 총 저장할 수있는 1000 개의 항목을 포함하는 3 개의 디렉토리를 깊이 제공합니다.
기타 운영 지점 :
dirWidth 값에 도달하면 다음 디렉토리가 생성됩니다.dirWidth 값에 도달하면 다음 상위 디렉토리가 생성됩니다.dirWidth 값에 도달하면 dirWidth 값이 무시됩니다. 쓰다
M.2 SSD 디스크가있는 노트북에서 Test-Fs.js 스크립트를 실행하면 다음 결과가 생성됩니다.
====================================================================================================
Testing scalable-blob-store with the following options:
blobStoreRoot: /tmp/blobs/test-fs
idFunction: ulid
dirDepth: 3
dirWidth: 1000
repeat: 10000
Beginning test...
====================================================================================================
Test complete.
====================================================================================================
{
blobStoreRoot: '/tmp/blobs/test-fs',
dirDepth: 3,
dirWidth: 1000,
runTimeMilliseconds: 83730,
totalDirectories: 12,
totalFiles: 10000,
totalBytes: 430000,
lastBlobPath: '/ckxwcwgwz0001lk9hgq8t9iup/ckxwcwgx00002lk9h6tbpdmq1/ckxwcy36m06yclk9hb0g92dwg/ckxwcy9ip07q4lk9h5uyl10k6'
}
====================================================================================================
Please remove /tmp/blobs/test-fs manually.
====================================================================================================
읽다
읽기 성능은 디스크 속도와 동일하지는 않지만 가깝습니다.
scalable-blob-store 내의 모든 Blobstore 방법은 약속을 반환합니다. 이는 비동기/대기업 기능과 함께 사용하는 데 적합합니다.
| API | 유형 | 보고 |
|---|---|---|
| 새로운 Blobstore (옵션) | 건설자 | Blobstore 인스턴스 |
| blobstore.blobstoreroot | 속성 만 읽으십시오 | String |
| blobstore.idfunction | 속성 만 읽으십시오 | Function |
| blobstore.dirdepth | 속성 만 읽으십시오 | Number |
| blobstore.dirwidth | 속성 만 읽으십시오 | Number |
| blobstore.getCurrentBloBdir () | 방법 | Promise<String> |
| blobstore.setcurrentblobdir (blobdir) | 방법 | Promise<undefined> |
| blobstore.createwritestream () | 방법 | Promise<Object> |
| blobstore.write (data, writeOptions) | 방법 | Promise<String> |
| Blobstore.append (Blobpath, 데이터, 부록) | 방법 | Promise<undefined> |
| blobstore.copy (blobpath, 깃발) | 방법 | Promise<String> |
| blobstore.createreadstream (blobpath) | 방법 | Promise<ReadStream> |
| blobstore.read (blobpath, readoptions) | 방법 | Promise<data> |
| blobstore.open (blobpath, 깃발, 모드) | 방법 | Promise<FileHandle> |
| Blobstore.realpath (Blobpath, RealPathoptions) | 방법 | Promise<String> |
| blobstore.stat (blobpath) | 방법 | Promise<Stats> |
| blobstore.exists (blobpath) | 방법 | Promise<Boolean> |
| Blobstore.remove (Blobpath) | 방법 | Promise<undefined> |
new BlobStore(options)유형 : 생성자 기능.
매개 변수 : Object 로서의 options .
반환 : 데이터를 저장하는 데 사용되는 새로운 BlobStore 객체.
설명:
new BlobStore(options) 에게 여러 번 전화하여 둘 이상의 Blob 매장을 만들 수 있습니다.
옵션은 생성자 기능으로 JavaScript object 로 전달됩니다.
| 열쇠 | 설명 | 기본값 |
|---|---|---|
blobStoreRoot | 블로브를 저장하는 루트 디렉토리 | 필수의 |
idFunction | 고유 한 ID 문자열을 반환하는 ID 함수 | 필수의 |
dirDepth | 뿌리 아래의 디렉토리를 얼마나 깊이 원하는지 | 3 |
dirWidth | 디렉토리의 최대 파일 또는 디렉토리 수 | 1000 |
예:
// Start by requiring the `scalable-blob-store` constructor function:
const BlobStore = require ( 'scalable-blob-store' ) ;
// You will need a unique ID function
const uuid = require ( 'uuid' ) ;
// Create the options object
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 4 ,
dirWidth : 2000 ,
} ;
// Create a blob store using the options `object`:
const blobStore = new BlobStore ( options ) ;여러 blob 매장 생성 :
const userOptions = {
blobStoreRoot : '/app/blobs/user' ,
idFunction : uuid . v4 ,
dirDepth : 4 ,
dirWidth : 2000 ,
} ;
const pdfOptions = {
blobStoreRoot : '/app/blobs/pdf' ,
idFunction : uuid . v4 ,
dirDepth : 2 ,
dirWidth : 300 ,
} ;
const userFileStore = new BlobStore ( userOptions ) ;
const pdfDocumentStore = new BlobStore ( pdfOptions ) ;blobStoreRoot유형 : 속성 만 읽습니다.
반환 : options.blobStoreRoot 과 일치하는 String .BloBstoreroot 값.
설명:
이것은 Blobstore 객체를 하위 모듈로 전달할 수있는 편의 속성입니다. 여전히 구성된 속성에 액세스 할 수 있습니다.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 4 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
console . log ( blobStore . blobStoreRoot ) ;
// Outputs '/app/blobs' which you configured in the optionsidFunction유형 : 속성 만 읽습니다.
반환 : options.idFunction 에서 구성한 고유 ID 기능.
설명:
이것은 Blobstore 객체를 하위 모듈로 전달할 수있는 편의 속성입니다. 여전히 구성된 속성에 액세스 할 수 있습니다.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 4 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
console . log ( blobStore . idFunction ( ) ) ;
// Outputs 'bac00ab2-5e6d-4b77-bfa4-e9befc3e4279' which is a generated UUID from the idFunction.dirDepth유형 : 속성 만 읽습니다.
반환 : options.dirDepth 일치하는 Number .
설명:
이것은 Blobstore 객체를 하위 모듈로 전달할 수있는 편의 속성입니다. 여전히 구성된 속성에 액세스 할 수 있습니다.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 4 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
console . log ( blobStore . dirDepth ) ;
// Outputs '4' which you configured in the optionsdirWidth유형 : 속성 만 읽습니다.
반환 : options.dirWidth 과 일치하는 Number .
설명:
이것은 Blobstore 객체를 하위 모듈로 전달할 수있는 편의 속성입니다. 여전히 구성된 속성에 액세스 할 수 있습니다.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 4 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
console . log ( blobStore . dirWidth ) ;
// Outputs '2000' which you configured in the optionsgetCurrentBlobDir()유형 : 메소드.
반환 : 현재 활성 Blob Creation Directory 인 String 로 해결되는 Promise .
설명:
이 기능은 BlobStore 가 내부적으로 사용하여 다음 Blob 파일이 디스크에 저장되는 디렉토리를 결정합니다.
BlobStore 외부에 Blob 파일을 저장 해야하는 경우이 방법을 사용하여 파일을 넣을 올바른 장소를 찾을 수 있습니다.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 3 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
async function main ( ) {
try {
console . log ( await blobStore . getCurrentBlobDir ( ) ) ;
// The 'dirDepth' option above is set to 3 so the output will be similar to the following:
// '/e44d3b0d-b552-4257-8b64-a53331184c38/443061b9-bfa7-40fc-a5a9-d848bc52155e/4d818f4c-88b3-45fd-a104-a2fc3700e9de'
} catch ( err ) {
console . error ( err ) ;
}
}
main ( ) ;setCurrentBlobDir(blobDir)유형 : 메소드.
매개 변수 : String 로서 blobDir .
blobStoreRoot 경로 아래에있는 Blob 파일을 저장하려는 파일 시스템 디렉토리 경로를 나타냅니다. 반환 : undefined 것으로 해결되는 Promise .
설명:
이 기능은 새로운 블로브 파일을 원하는 blobPath 에 저장하기 위해 BlobStore 안내하는 데 사용될 수 있습니다.
scalable-blob-store 의 한 가지 문제는 많은 블로브 파일을 제거하면 파일에 위치한 디렉토리가 제거되지 않는다는 것입니다. 디렉토리를 직접 제거하거나 현재 활성 Blob 디렉토리를 설정하여 새 블로브 파일로 다시 채울 수 있습니다.
이 기능은이 모듈의 소비자가 빈 블로브 디렉토리를 중심으로 작업 할 수 있도록 추가되었습니다.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 3 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
async function main ( ) {
try {
console . log ( await blobStore . getCurrentBlobDir ( ) ) ;
// The 'dirDepth' option above is set to 3 so the output will be similar to the following:
// '/e44d3b0d-b552-4257-8b64-a53331184c38/443061b9-bfa7-40fc-a5a9-d848bc52155e/4d818f4c-88b3-45fd-a104-a2fc3700e9de'
await blobStore . setCurrentBlobDir ( '/some/blob/path' ) ;
console . log ( await blobStore . getCurrentBlobDir ( ) ) ;
// Outputs '/some/blob/path' to the console.
// Any new blob files added to the blob store will go into this path until there are `dirWidth` or 2000 files within it.
} catch ( err ) {
console . error ( err ) ;
}
}
main ( ) ;createWriteStream()유형 : 메소드.
반환 : Blob Store Root 및 Writestream 내의 파일로의 자식 경로가 포함 된 Object 로 해결되는 Promise .
설명:
다음은 uuid를 idfunction으로 사용하여 반환 된 객체의 exampe입니다.
{
blobPath : "/e6b7815a-c818-465d-8511-5a53c8276b86/aea4be6a-9e7f-4511-b394-049e68f59b02/fea722d1-001a-4765-8408-eb8e0fe7dbc6/183a6b7b-2fd6-4f80-8c6a-2647beb7bb19" ,
writeStream : stream . Writable
} writeStream 사용하여 블로브 또는 파일을 저장하십시오. 향후 액세스를 위해 blobPath 데이터베이스에 저장해야합니다.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 3 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
// The below readStream is simply to make this a complete example
const fs = require ( 'fs' ) ;
const readStream = fs . createReadStream ( '/path/to/file' ) ;
async function main ( ) {
let result ;
try {
result = await blobStore . createWriteStream ( ) ;
} catch ( err ) {
console . error ( err ) ;
}
console . dir ( result ) ;
// result object will be similar to this:
// {
// blobPath: "/e6b7815a-c818-465d-8511-5a53c8276b86/aea4be6a-9e7f-4511-b394-049e68f59b02/fea722d1-001a-4765-8408-eb8e0fe7dbc6/183a6b7b-2fd6-4f80-8c6a-2647beb7bb19",
// writeStream: [WriteStream]
// }
// Using a Promise to encapsulate the write asynchronous events.
await new Promise ( ( resolve , reject ) => {
result . writeStream . on ( 'finish' , ( ) => {
resolve ( ) ;
} ) ;
result . writeStream . on ( 'error' , reject ) ;
readStream . pipe ( result . writeStream ) ;
} ) ;
console . log ( blobPath ) ;
// Logs the blobPath. Save this in your database.
}
main ( ) ;write(data, writeOptions)유형 : 메소드.
매개 변수 : String , Buffer , TypedArray 또는 DataView 로서의 data .
매개 변수 : writeOptions as Object 입니다.
writeOptions 객체는 인코딩, 모드 및 플래그 속성을 지원합니다. 반환 : String 로 해결되는 Promise .
blobPath 값이 포함되어 있습니다.설명:
데이터 스트림이 아닌 간단한 데이터가있는 경우이 메소드를 사용하여 데이터를 Blob 파일에 저장할 수 있습니다.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 3 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
async function main ( ) {
const data = 'The quick brown fox jumps over the lazy dog.' ;
try {
const blobPath = await blobStore . write ( data ) ;
// The returned blobPath will look something like this:
// '/e44d3b0d-b552-4257-8b64-a53331184c38/443061b9-bfa7-40fc-a5a9-d848bc52155e/4d818f4c-88b3-45fd-a104-a2fc3700e9de'
// Save it to your database.
} catch ( err ) {
console . error ( err ) ;
}
}
main ( ) ;append(blobPath, data, appendOptions)유형 : 메소드.
매개 변수 : String 로서 blobPath .
blobPath 검색하십시오. 매개 변수 : String 또는 Buffer 로서의 data .
매개 변수 : Object 로서 appendOptions .
appendOptions 객체는 인코딩, 모드 및 플래그 속성을 지원합니다. 반환 : undefined 사람으로 해결되는 Promise .
설명:
이 방법을 사용하여 블로브 파일 끝에 메모리 데이터에 간단한 추가를 추가하십시오.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 3 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
async function main ( ) {
const data = 'The quick brown fox jumps over the lazy dog.' ;
try {
await blobStore . append ( data ) ;
} catch ( err ) {
console . error ( err ) ;
}
}
main ( ) ;copy(blobPath, flags)유형 : 메소드.
매개 변수 : String 로서 blobPath .
blobPath 검색하십시오. 매개 변수 : Number 로 flags .
반환 : String 로 해결되는 Promise .
blobPath 값입니다.설명:
이 방법을 사용하여 기존 Blob 파일의 사본을 만듭니다.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 3 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
async function main ( ) {
try {
const blobPathSource =
'/e6b7815a-c818-465d-8511-5a53c8276b86/aea4be6a-9e7f-4511-b394-049e68f59b02/fea722d1-001a-4765-8408-eb8e0fe7dbc6/183a6b7b-2fd6-4f80-8c6a-2647beb7bb19' ;
const blobPathDest = await blobStore . copy ( blobPathSource ) ;
// Store your new blobPath into your application database
} catch ( err ) {
console . error ( err ) ;
}
}
main ( ) ;createReadStream(blobPath)유형 : 메소드.
매개 변수 : String 로서 blobPath .
blobPath 검색하십시오. 반환 : ReadStream 으로 해결되는 Promise .
설명:
blobPath 에있는 Blob 파일에 읽을 수있는 스트림을 만듭니다.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 3 ,
dirWidth : 2000 ,
} ;
async function main ( ) {
// Get the blobPath value from your database.
const blobPath =
'/e6b7815a-c818-465d-8511-5a53c8276b86/aea4be6a-9e7f-4511-b394-049e68f59b02/fea722d1-001a-4765-8408-eb8e0fe7dbc6/183a6b7b-2fd6-4f80-8c6a-2647beb7bb19h' ;
let readStream ;
try {
readStream = await blobStore . createReadStream ( blobPath ) ;
} catch ( err ) {
console . error ( err ) ;
}
readStream . on ( 'error' , ( err ) => {
console . error ( err ) ;
} ) ;
// Blob contents is piped to the console.
readStream . pipe ( process . stdout ) ;
}
main ( ) ;read(blobPath, readOptions)유형 : 메소드.
매개 변수 : String 로서 blobPath .
blobPath 검색하십시오. 매개 변수 : Object 로서 readOptions .
반환 : Blob 파일의 내용으로 해결되는 Promise .
scalable-blob-store 기본적으로 readOptions.encoding 값을 'UTF8'으로 설정합니다.설명:
이 메소드를 사용하여 작은 Blob 파일의 내용을 메모리에 읽으십시오.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 3 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
async function main ( ) {
try {
// Retrieve the blobPath value from your database
const blobPath =
'/e6b7815a-c818-465d-8511-5a53c8276b86/aea4be6a-9e7f-4511-b394-049e68f59b02/fea722d1-001a-4765-8408-eb8e0fe7dbc6/183a6b7b-2fd6-4f80-8c6a-2647beb7bb19' ;
const content = await blobStore . read ( blobPath ) ;
// Do something with the content
} catch ( err ) {
console . error ( err ) ;
}
}
main ( ) ;open(blobPath, flags, mode)유형 : 메소드.
매개 변수 : String 로서 blobPath .
blobPath 검색하십시오. 매개 변수 : String 또는 Number 로 flags .
반환 : 파일 핸들 객체로 해결되는 Promise .
설명:
이것은 Blob 파일에 대해 많은 파일 작업을 수행 할 수있는보다 고급 방법입니다.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 3 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
async function main ( ) {
try {
// Retrieve the blobPath value from your database
const blobPath =
'/e6b7815a-c818-465d-8511-5a53c8276b86/aea4be6a-9e7f-4511-b394-049e68f59b02/fea722d1-001a-4765-8408-eb8e0fe7dbc6/183a6b7b-2fd6-4f80-8c6a-2647beb7bb19' ;
const fileHandle = await blobStore . open ( blobPath ) ;
// Do something with the file handle object
// See the documentation for more detail
// The documentation link is in the description above
} catch ( err ) {
console . error ( err ) ;
}
}
main ( ) ;realPath(blobPath, realPathOptions)유형 : 메소드.
매개 변수 : String 로서 blobPath .
blobPath 검색하십시오. 매개 변수 : String 또는 Object 로서 realPathOptions .
반환 : String 로 해결되는 Promise .
설명:
이 메소드를 사용하여 파일 시스템에서 Blob 파일을 찾으십시오. 전체 Blob 파일 경로를 결정할 수 있으므로이 방법은 실제로 필요하지 않아야합니다. Blobstoreroot와 Blobpath 값을 단순히 연결하십시오.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 3 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
async function main ( ) {
try {
// Retrieve the blobPath value from your database
const blobPath =
'/e6b7815a-c818-465d-8511-5a53c8276b86/aea4be6a-9e7f-4511-b394-049e68f59b02/fea722d1-001a-4765-8408-eb8e0fe7dbc6/183a6b7b-2fd6-4f80-8c6a-2647beb7bb19' ;
const fsPath = await blobStore . realPath ( blobPath ) ;
// With the above options the result will be similar to this:
// '/app/blobs/e6b7815a-c818-465d-8511-5a53c8276b86/aea4be6a-9e7f-4511-b394-049e68f59b02/fea722d1-001a-4765-8408-eb8e0fe7dbc6/183a6b7b-2fd6-4f80-8c6a-2647beb7bb19
} catch ( err ) {
console . error ( err ) ;
}
}
main ( ) ;stat(blobPath)유형 : 메소드.
매개 변수 : String 로서 blobPath .
반환 : 통계 Object .
설명:
파일 시스템 stats 개체를 구문 분석하는 대신 scalable-blob-store 원시 stats 개체를 반환합니다.
더 많은 STAT 클래스 세부 사항은 Wikipedia에서 찾을 수 있습니다.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 3 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
async function main ( ) {
try {
// Retrieve the blobPath value from your database
const blobPath =
'/e6b7815a-c818-465d-8511-5a53c8276b86/aea4be6a-9e7f-4511-b394-049e68f59b02/fea722d1-001a-4765-8408-eb8e0fe7dbc6/183a6b7b-2fd6-4f80-8c6a-2647beb7bb19' ;
const stats = await blobStore . stat ( blobPath ) ;
console . dir ( stats ) ;
// Console output will be similar to the following.
// { dev: 2050,
// mode: 33188,
// nlink: 1,
// uid: 1000,
// gid: 1000,
// rdev: 0,
// blksize: 4096,
// ino: 6707277,
// size: 44,
// blocks: 8,
// atime: Mon Oct 12 2015 08:51:29 GMT+1000 (AEST),
// mtime: Mon Oct 12 2015 08:51:29 GMT+1000 (AEST),
// ctime: Mon Oct 12 2015 08:51:29 GMT+1000 (AEST),
// birthtime: Mon Oct 12 2015 08:51:29 GMT+1000 (AEST) }
} catch ( err ) {
console . error ( err ) ;
}
}
main ( ) ;exists(blobPath)유형 : 메소드.
매개 변수 : String 로서 blobPath .
반품 : Boolean
true , 그렇지 않으면 false .설명:
이 방법을 사용하여 간단한 Blob 파일 존재 테스트에 사용하십시오.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 3 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
async function main ( ) {
try {
// Retrieve the blobPath value from your database
const blobPath =
'/e6b7815a-c818-465d-8511-5a53c8276b86/aea4be6a-9e7f-4511-b394-049e68f59b02/fea722d1-001a-4765-8408-eb8e0fe7dbc6/183a6b7b-2fd6-4f80-8c6a-2647beb7bb19' ;
const exists = await blobStore . exists ( blobPath ) ;
// The result will be either true or false depending if the blob file exists.
} catch ( err ) {
console . error ( err ) ;
}
}
main ( ) ;remove(blobPath)유형 : 메소드.
매개 변수 : String 로서 blobPath .
반환 : 아무것도 잘못되지 않았거나 파일이 존재하지 않으면 undefined .
설명:
이 방법을 사용하여 Blob 파일을 삭제하십시오. 이 방법은 디렉토리를 제거하는 데 사용할 수 없습니다.
예:
const BlobStore = require ( 'scalable-blob-store' ) ;
const uuid = require ( 'uuid' ) ;
const options = {
blobStoreRoot : '/app/blobs' ,
idFunction : uuid . v4 ,
dirDepth : 3 ,
dirWidth : 2000 ,
} ;
const blobStore = new BlobStore ( options ) ;
async function main ( ) {
try {
// Retrieve the blobPath value from your database
const blobPath =
'/e6b7815a-c818-465d-8511-5a53c8276b86/aea4be6a-9e7f-4511-b394-049e68f59b02/fea722d1-001a-4765-8408-eb8e0fe7dbc6/183a6b7b-2fd6-4f80-8c6a-2647beb7bb19' ;
await blobStore . remove ( blobPath ) ;
// The blob file will no longer exist
} catch ( err ) {
console . error ( err ) ;
}
}
main ( ) ; scalable-blob-store 에는 사소한 문제가 있습니다. 많은 수의 Blob 파일이 추가 된 다음 Blob Store에서 제거 된 경우 소수의 파일이있는 빈 디렉토리 또는 디렉토리가있을 수 있습니다. 이 디렉토리는 제거되지 않으며 채워지지 않습니다.
빈 또는 드문 인구가 많은 디렉토리를 방지하려면 blobStoreRoot 디렉토리에 대해 유지 보수 작업을 실행해야합니다. 이 유지 보수 작업은 빈 또는 불완전한 디렉토리를 찾아 빈 blobPath 를 전달하는 SetCurrentBlobdir 메소드를 호출해야합니다.
응용 프로그램의 경우 많은 수의 Blob 파일을 거의 제거하지 않을 수 있습니다. 이 경우이 문제를 무시할 수 있습니다.
scalable-blob-store 테스트하는 두 가지 방법이 있습니다.
os.tmpdir() 디렉토리를 사용하는 단위 테스트 . scalable-blob-store 복제 한 후 다음을 콘솔에 입력하십시오.
npm install
npm test
test-fs.js 파일을 실행하면 임시 디렉토리에 ~/blobs 디렉토리가 생성 된 다음 많은 블로브로 재귀 적으로 채워집니다.
test-fs.js 파일에 구성된 기본 옵션은 다음과 같습니다.
const opts = {
blobStoreRoot : os . tmpdir ( ) + '/blobs' ,
idFunction : cuid ,
dirDepth : 3 ,
dirWidth : 1000 ,
} ;
const repeat = 10000 ;다른 결과를 보려면 옵션을 변경하십시오.
scalable-blob-store 복제 한 후 다음을 콘솔에 입력하십시오.
npm install
node ./tests/test-fs.js
완료되면 /tmp/blobs 디렉토리를 검사하십시오. 대상 디렉토리 내의 디렉토리 및 파일 요약을 제공하는 트리 명령을 사용하는 것이 좋습니다.
tree ~ /blobs
tree -d ~ /blobs
그랜트 카르타 우 (Grant Carthew)는 호주 퀸즈랜드 (Queensland)의 기술자입니다. 나는 여러 개인 프로젝트에서 코드 작업을하고 있으며 필요가 발생하면 나만의 패키지를 만듭니다.
이 프로젝트는 규모가 규모가 높을 수있는 현지 Blob 매장이 필요했기 때문에 존재합니다.
내가 오픈 소스로하는 모든 일은 내 시간에 그리고 오픈 소스 커뮤니티에 대한 기여로 이루어집니다.
내 프로젝트를 사용하고 있고 감사하거나 지원하고 싶다면 아래 Patreon 링크를 클릭하십시오.
NPM의 다른 프로젝트를 참조하십시오.
git checkout -b my-new-feature 만듭니다git commit -am 'Add some feature'git push origin my-new-featurenode-uuid uuid 로 대체했습니다.ES5 빌드 코드 사용으로 전환했습니다. NODEJS 엔진 요구 사항이 제거되었습니다.return null 진술.return null 추가했습니다.es5dist 추가되었습니다. 패키지가 업데이트되었습니다.MIT