Skip to content

Latest commit

 

History

History
481 lines (364 loc) · 20.6 KB

README.md

File metadata and controls

481 lines (364 loc) · 20.6 KB

Mobiletto

Mobiletto nububiko bwa JavaScript ububiko, hamwe nubushake bwabakiriya-kuruhande rwibanga.

Ibirimo

  • [Kuki Mobiletto?](# Kuki-Mobiletto?)
  • [Gutangira vuba](# Byihuse-gutangira)
  • [Mobiletto CLI](# mobiletto-umukiriya)
  • [Inkomoko](# Inkomoko)
  • [Kwinjiza](# Kwinjiza)
  • [Inkunga n'inkunga](# Inkunga-na-Inkunga)
  • [Ikoreshwa ryibanze](# Shingiro-imikoreshereze)
  • [Metadata](# Metadata)
  • [Ubundi buryo bwo gutumiza mu mahanga](# Ubundi buryo-bwo gutumiza mu mahanga)
  • [Cishing](# Cishing)
  • [Indorerwamo](# Indorerwamo)
  • [Gucisha mu mucyo](# Transparent-encryption)
  • [Urufunguzo ruzunguruka](# Urufunguzo-ruzunguruka)
  • [Imigaragarire yumushoferi](# Umushoferi-Imigaragarire)
  • [Kwinjira](# Kwinjira)

Soma ibi mu rundi rurimi

Iyi nyandiko README.md yarahinduwe, binyuze kuri hokeylisation, muri ** ururimi rwose rushyigikiwe na Google Translate! **

Nzi neza ko bidatunganye, ariko nizere ko biruta ubusa!

[🇸🇦 Icyarabu](docs / ar / README.md) [🇧🇩 Ikibengali](docs / bn / README.md) [🇩🇪 Ikidage](docs / de / README.md) [🇺🇸 Icyongereza](docs / en / README.md) [🇪🇸 Icyesipanyoli](docs / es / README.md) [🇫🇷 Igifaransa](docs / fr / README.md) [🇹🇩 Hausa](docs / ha / README.md) [🇮🇳 Hindi](docs / hi / README.md) [🇮🇩 Indoneziya](docs / id / README.md) [🇮🇹 Umutaliyani](docs / it / README.md) [🇯🇵 Ikiyapani](docs / ja / README.md) [🇰🇷 Igikoreya](docs / ko / README.md) [🇮🇳 Marathi](docs / mr / README.md) [Ish Igipolonye](docs / pl / README.md) [🇧🇷 Igiporutugali](docs / pt / README.md) [🇷🇺 Ikirusiya](docs / ru / README.md) [Wa Igiswahiri](docs / sw / README.md) [🇵🇭 Tagalog](docs / tl / README.md) [🇹🇷 Turukiya](docs / tr / README.md) [🇵🇰 Urdu](docs / ur / README.md) [🇻🇳 Abanya Viyetinamu](docs / vi / README.md) [🇨🇳 Igishinwa](docs / zh / README.md)

** [📚 ... Indimi zose ...](docs / README.md) **

Hari ikibazo cyubu busobanuro bwa README?

Ubu busobanuro bwihariye bwumwimerere README irashobora kuba ifite inenge - * gukosora biremewe cyane! * Nyamuneka ohereza gukurura icyifuzo kuri GitHub, cyangwa niba utishimiye gukora ibyo, fungura ikibazo

Mugihe uremye ikibazo gishya cya GitHub kubyerekeye ubusobanuro, nyamuneka kora:

  • shyiramo urupapuro rwa URL (kopi / komatanya uhereye kuri aderesi ya aderesi)
  • shyiramo inyandiko nyayo itariyo (kopi / komatanya kuri mushakisha)
  • nyamuneka sobanura ibitagenda neza - ubusobanuro ntabwo aribwo? imiterere yacitse kuburyo runaka?
  • mutange igitekerezo cyo gusobanura neza, cyangwa uburyo inyandiko igomba guhindurwa neza
  • ** Urakoze! **

Kuki Mobiletto?

Muraho neza umucuruzi ufunguye!

Abatanga ibicu bitandukanye bitandukanye bafite API zidahuye. Ndetse nabaharanira "S3 guhuza" kugira imyitwarire idasanzwe.

Iyo uhisemo umucuruzi wububiko runaka kuri porogaramu yawe, niba wanditse kode kuri API yabo, porogaramu yawe ubu biterwa na serivisi. Mugihe cyigihe kandi code ikarundanya, guhindura abacuruzi biba bigenda bidashoboka. Murakaza neza ku isi ishimishije y'abacuruzi gufunga!

Mobiletto yagenewe gukemura iki kibazo. Ukoresheje porogaramu yawe kuri API ya mobiletto, urashobora byoroshye hindura abatanga ububiko kandi umenye ko ububiko bwa porogaramu yawe izitwara kimwe.

Ikizamini kinini

Abashoferi bose bapimwe imyitwarire imwe hamwe na 60+ ibizamini kuri buri shoferi. Turagerageza abashoferi bose hamwe nibihuza byose:

  • Encryption: byombi birashoboka kandi byahagaritswe
  • Redis cache: byombi birashoboka kandi birahagarikwa

Ubu buryo buduha amahoro-yumutima ko mobiletto izitwara kimwe utitaye kumushoferi ukoresha, kandi utitaye ko ushobora gukora cishing na / cyangwa encryption.

Inkunga yabatwara

Abashoferi ba mobiletto y'ubu:

  • s3 : Amazon S3

  • b2 : Gusubira inyuma B2

  • local : sisitemu yimikorere

  • Umusanzu wo gushyigikira abatanga ibicu byinshi murakaza neza! *

mobiletto-umukiriya

Mobiletto igenewe gukoreshwa nkisomero nizindi code ya JavaScript.

Gukorana na mobiletto kumurongo wumurongo, koresha mobiletto-umukiriya

Inkomoko

Inkunga ninkunga

Ndagerageza kuba umuhanga ufungura isoko yumwuga. Nakoraga inganda za software imyaka myinshi, natangiye ibigo byatsinze ndabigurisha mubigo bya leta. Mperutse kubura akazi, kandi rwose nta kindi gikorwa mfite ku murongo

Ngiye rero kugerageza kwandika software ifasha ndebe niba ibyo bikora

Niba ukunda gukoresha iyi software, ndagushimira cyane kubwa ntoya umusanzu wa buri kwezi ukoresheje Patreon

  • Urakoze! *

Kwinjiza

Shyiramo ukoresheje npm yarn . Birashoboka ko ushaka verisiyo ya lite itarimo byose byahinduwe dosiye ya README:

npm install mobiletto-lite
yarn add mobiletto-lite

Niba rwose ushaka dosiye zo GUSOMA mururimi rwose, shyiramo verisiyo yuzuye:

npm install mobiletto
yarn add mobiletto

Tangira vuba

Urugero rugufi ukoresheje mobiletto s3 .

Iyi code yakora kimwe niba umushoferi yari b2 local .

const storage = require('mobiletto')
const bucket = await storage.connect('s3', aws_key, aws_secret, {bucket: 'bk'})

// list objects: returns array of metadata objects
const listing = await bucket.list()
const dirList = await bucket.list('some/dir/')
const everything = await bucket.list('', {recursive: true})

// write an entire file
let bytesWritten = await bucket.writeFile('some/path', someBufferOfData)

// write a file from a stream/generator
bytesWritten = await bucket.write('some/path', streamOrGenerator)

// read an entire file
// returns null if an exception would otherwise be thrown
const bufferOrNull = await bucket.safeReadFile('some/path')

// stream-read a file, passing data to callback
const bytesRead = await bucket.read('some/path', (chunk) => { ...do something with chunk... } )

// remove a file, returns the path removed
let removed = await bucket.remove('some/path') // removed is a string

// remove a directory, returns array of paths removed
removed = await bucket.remove('some/directory', {recursive: true}) // removed is now an array!

Ikoreshwa ryibanze

Urugero runini cyane, rwerekana byinshi mubiranga byatanzwe:

const { mobiletto } = require('mobiletto')

// General usage
const api = await mobiletto(driverName, key, secret, opts)

// To use 'local' driver:
// * key: base directory
// * secret: ignored, can be null
// * opts object:
// * readOnly: optional, never change anything on the filesystem; default is false
// * fileMode: optional, permissions used when creating new files, default is 0600. can be string or integer
// * dirMode: optional, permissions used when creating new directories, default is 0700. can be string or integer
const local = await mobiletto('local', '/home/ubuntu/tmp', null, {fileMode: 0o0600, dirMode: '0700'})

// To use 's3' driver:
// * key: AWS Access Key ID
// * secret: AWS Secret Key
// * opts object:
// * readOnly: optional, never change anything on the bucket; default is false
// * bucket: required, name of the S3 bucket
// * region: optional, the AWS region to communicate with, default is us-east-1
// * prefix: optional, all read/writes within the S3 bucket will be under this prefix
// * delimiter: optional, directory delimiter, default is '/' (note: always '/' when encryption is enabled)
const s3 = await mobiletto('s3', aws_key, aws_secret, {bucket: 'bk', region: 'us-east-1'})

// To use 'b2' driver:
// * key: Backblaze Key ID
// * secret: Backblaze Application Key
// * opts object:
// * readOnly: optional, never change anything on the bucket; default is false
// * bucket: required, the ID (**not the name**) of the B2 bucket
// * prefix: optional, all read/writes within the B2 bucket will be under this prefix
// * delimiter: optional, directory delimiter, default is '/' (note: always '/' when encryption is enabled)
// * partSize: optional, large files will be split into chunks of this size when uploading
const b3 = await mobiletto('b2', b2_key_id, b2_app_key, {bucket: 'bk', partSize: 10000000})

// List files
api.list() // --> returns an array of metadata objects

// List files recursively
api.list({ recursive: true })

// List files in a directory
const path = 'some/path'
api.list(path)
api.list(path, { recursive: true }) // also supports recursive flag

// Visit files in a directory -- visitor function must be async
api.list(path, { visitor: myAsyncFunc })
api.list(path, { visitor: myAsyncFunc, recursive: true })

// The `list` method throws MobilettoNotFoundError if the path does not exist
// When you call `safeList` on a non-existent path, it returns an empty array
api.safeList('/path/that/does/not/exist') // returns []

// Read metadata for a file
api.metadata(path) // returns metadata object

// The `metadata` method throws MobilettoNotFoundError if the path does not exist
// When you call `safeMetadata` on a non-existent path, it returns null
api.safeMetadata('/tmp/does_not_exist') // returns null

// Read a file
// Provide a callback that writes the data someplace
const callback = (chunk) => { ... write chunk somewhere ... }
api.read(path, callback) // returns count of bytes read

// Read an entire file at once
const data = await api.readFile(path) // returns a byte Buffer of the file contents

// Read an entire file at once
// returns null if an exception would otherwise be thrown
const bufferOrNull = await bucket.safeReadFile('some/path')

// Write a file
// Provide a generator function that yields chunks of data
const generator = function* () {
  while ( ... more-data-to-return ... ) {
    data = ... load-data ...
    yield data
  }
}
local.api(path, generator) // returns count of bytes written

// Write an entire file at once (convenience method)
await api.writeFile(path, bufferOrString) // returns count of bytes written

// Delete a file
// Quiet param is optional (default false), when set errors will not be thrown if the path does not exist
// Always returns a value or throws an error.
// Return value may be a single string of the file removed, or an array of all files removed (driver-dependent)
const quiet = true
api.remove(path, {quiet}) // returns single path removed

// Recursively delete a directory and do it quietly (do not report errors)
const recursive = true
const quiet = true
api.remove(path, {recursive, quiet}) // returns array of paths removed

Metadata

Itegeko rya " metadata " risubiza metadata kubyerekeye kwinjiza dosiye imwe. Mu buryo nk'ubwo, kugaruka agaciro kuva kuri list command ni umurongo wibintu bya metadata.

Ikintu cya metadata gisa nkiki:

{
  "name": "fully/qualified/path/to/file",
  "type": "entry-type",
  "size": size-in-bytes,
  "ctime": creation-time-epoch-millis,
  "mtime": modification-time-epoch-millis
}

Umutungo wa type urashobora kuba file , dir , link , cyangwa special .

Ukurikije ubwoko bwa shoferi, itegeko rya " list " ntirishobora gusubiza imirima yose. type name igomba guhora ihari. Ibikurikira metadata itegeko rizasubiza ibintu byose biboneka.

Ubundi buryo bwo gutumiza mu mahanga

Kuzana module yuzuye kandi ukoreshe imikorere ya connect :

const storage = require('mobiletto')
const opts = {bucket: 'bk', region: 'us-east-1'}
const s3 = await storage.connect('s3', aws_key, aws_secret, opts)
const objectData = await s3.readFile('some/path')

Cishing

Mobiletto ikora neza hamwe na cache itukura.

Mobiletto izagerageza guhuza nurugero rwa redis kuri 127.0.0.1:6379

Urashobora guhisha kimwe muribi:

  • Shiraho MOBILETTO_REDIS_HOST env var, mobiletto ihuza hano aho kubahost
  • Shiraho MOBILETTO_REDIS_PORT env var, iki cyambu kizakoreshwa

Mobiletto izabika imfunguzo zayo zose za redis hamwe _mobiletto__ . Urashobora guhindura ibi mugushiraho MOBILETTO_REDIS_PREFIX env var.

Urashobora kandi gushiraho kuri buri guhuza cashe hamwe na opts.redisConfig ikintu:

const redisConfig = {
    enabled: true, // optional, default is true. if false other props are ignored
    host: '127.0.0.1',
    port: 6379,
    prefix: '_mobiletto__'
}
const opts = { redisConfig, bucket: 'bk', region: 'us-east-1' }
const s3 = await storage.connect('s3', aws_key, aws_secret, opts)

Ntushaka gufunga redis?

Kugirango uhagarike: pass enabled: false mubintu opts.redisConfig mugihe ushizeho isano yawe.

Nkuko byaganiriweho hepfo, guhagarika cishing bizagira ingaruka mbi kumikorere no gutanga ibyifuzo byinshi kubika ukeneye rwose.

Cishing ubuyobozi

** Ububiko bwabitswe **: gusoma / kwandika ububiko bwabitswe ni buhoro buhoro kurenza ibisanzwe, ariko kugendagenda mububiko (ibyo ibintu bimwe bikora) bihenze rwose. Gukoresha cache bizaguha imbaraga zingirakamaro.

Ubusanzwe cache ifite umutekano, ariko ntabwo ikora neza niba ufite byinshi byo kwandika / gukuraho ibikorwa. Kwandika cyangwa gukuraho ibikorwa byose bitesha agaciro cache yose, kwemeza ko ibisomwa bizakurikiraho bizabona impinduka ziheruka.

ibikoresho bya CLI

Niba ukoresha igikoresho cya CLI nka mobiletto-umukiriya, uzashaka rwose redis cache ishoboye, nkuko imara igihe cyo gutabaza kwa mo .

Indorerwamo

// Copy a local filesystem mobiletto to S3
s3.mirror(local)

// Mirror a local subdirectory from one mobiletto to an S3 mobiletto, with it's own subdirectory
local.mirror(s3, 'some/local-folder', 'some/s3-folder')

Itegeko rya mirror rikora kopi yigihe kimwe cya dosiye zose kuva mobiletto kugeza kurindi. Ntabwo ikora inzira iyo ari yo yose yo kubungabunga indorerwamo mugihe. Ongera ukoreshe itegeko rya mirror guhuza dosiye zose zabuze.

Garuka agaciro kiva muri mirror cyoroshye hamwe na compte yama dosiye menshi yagenze neza indorerwamo nangahe dosiye zagize amakosa:

{
  success: count-of-files-mirrored,
  errors: count-of-files-with-errors
}

UMUBURO: Kwerekana amakuru manini yamakuru birashobora kugutwara igihe kandi bikaguka cyane

Hamwe na mirror call semantics birashobora rimwe na rimwe kwitiranya kumva uwariwe umusomyi ninde wanditse. Tekereza nkibisobanuro byatanzwe: "ibumoso-mobiletto" ni ikintu gihabwa (amakuru yindorerwamo yanditse), na "iburyo-mobiletto" (the impaka kuri mirror method) nigiciro gihabwa (amakuru yindorerwamo arasomwa).

Igenzura risobanutse

Gushoboza umukiriya kuruhande rwibanga:

// Pass encryption parameters
const encryption = {
  // key is required, must be >= 16 chars
  key: randomstring.generate(128),

  // optional, the default is to derive IV from key
  // when set, IV must be >= 16 chars
  iv: randomstring.generate(128),

  // optional, the default is aes-256-cbc
  algo: 'aes-256-cbc'
}
const api = await mobiletto(driverName, key, secret, opts, encryption)

// Subsequent write operations will encrypt data (client side) when writing
// Subsequent read operations will decrypt data (client side) when reading

Bigenda bite? Ububiko bwihariye "ububiko bwinjira" (dirent) ububiko (encrypted) bukurikirana dosiye zirimo ububiko (bita dirent diregiteri).

  • "Urutonde" itegeko risoma ububiko list yinjira, yandika buri nzira yanditse; hanyuma asubize metadata kuri buri dosiye
  • list amategeko ntagikora cyane cyane kububiko bufite umubare munini wamadosiye
  • Itegeko rya "andika" ryandika dosiye ya write muri diregiteri ya buri mubyeyi, inshuro nyinshi; hanyuma wandike dosiye
  • write amategeko azashyiramo O (N) yanditse, hamwe na N = ubujyakuzimu mubuyobozi bukurikirana
  • ' remove itegeko rikuraho dosiye ya dirent ijyanye, hamwe nababyeyi niba ari ubusa, byongeye; hanyuma ikuraho dosiye
  • Kudasubiramo remove amategeko bizatera O (N) gusoma kandi birashoboka nkibisiba byinshi, hamwe na N = ubujyakuzimu mubuyobozi bukurikirana
  • Gusubiramo remove amategeko kuri sisitemu nini kandi yimbitse ya dosiye irashobora kubahenze

Menya ko nubwo hamwe nabakiriya kuruhande rwibanga rushoboye, umwanzi ufite igaragara ryuzuye muri seriveri yawe-ibanga ububiko, nubwo nta rufunguzo, burashobora kubona umubare wububiko hamwe nangahe dosiye ziri muri buri, hamwe na imbaraga, kuvumbura bimwe cyangwa byose muburyo rusange bwububiko bukurikirana.

  • Icyitonderwa: Koresha imiterere isa neza kugirango umutekano urusheho kuba mwiza. * Umwanzi ntabwo yamenya amazina yububiko / dosiye keretse niba nabo bari bazi encryption yawe urufunguzo cyangwa ubundi buryo bwatsinze neza ibanga. Bets zose zirahari noneho!

Imikorere na cishing

Ibikorwa kububiko bwabitswe birashobora gutinda. Urutonde rusubirwamo no kuvanaho birashobora gutinda cyane. Gufata ukoresheje redis bifasha cyane, ariko menya ko cache ihindurwamo inyandiko zose cyangwa ikuraho.

Kuzenguruka urufunguzo

Kora mobiletto hamwe nurufunguzo rwawe rushya, hanyuma indorerwamo amakuru ashaje muri yo:

const storage = require('mobiletto')

const oldEncryption = { key: .... }
const oldStorage = await storage.connect('s3', aws_key, aws_secret, {bucket: 'bk', region: 'us-east-1'}, oldEncryption)

const newEncryption = { key: .... }
const newStorage = await storage.connect('s3', aws_key, aws_secret, {bucket: 'zz', region: 'us-east-1'}, newEncryption)

newStorage.mirror(oldStorage) // if oldStorage is very large, this may take a looooooong time...

Imigaragarire yabatwara

Umushoferi ni dosiye iyo ari yo yose ya JS yohereza hanze 'ububikoClient' imikorere hamwe nuyu mukono:

function storageClient (key, secret, opts)
  • key : umugozi, urufunguzo rwa API ( local bubiko bwibanze)
  • secret : umugozi, ibanga rya API yawe (rishobora gusibwa local shoferi)
  • opts : ikintu, imitungo ni kuri buri shoferi:
  • Kuri local , imitungo ya ' fileMode dirMode igena uburyo bushya bwo gukora dosiye nububiko byakozwe
  • Kuri s3 , umutungo wa ' bucket urakenewe. Ibintu bidahitamo ni:
    • region: the S3 region, default is us-east-1
    • prefix: a prefix to prepend to all S3 paths, default is the empty string
    • delimiter: the directory delimiter, default is '/'

Ikintu ububiko bwibikorwa bigaruka bigomba gusobanura iyi mirimo:

// Test the driver before using, ensure proper configuration
async testConfig ()

// List files in path (or from base-directory)
// If recursive is true, list recursively
// If visitor is defined, it will be an async function. await the visitor function on each file found
// Otherwise, perform the listing and return an array of objects
async list (path, recursive = false, visitor = null) // path may be omitted

// Read metadata for a path
async metadata (path)

// Read a file
// callback receives a chunk of data. endCallback is called at end-of-stream
async read (path, callback, endCallback = null)

// Write a file
// driver must be able to handle a generator or a stream
async write (path, generatorOrReadableStream)

// Remove a file, or recursively delete a directory
// returns a string of a single path removed, or an array of multiple paths removed
async remove (path, recursive = false, quiet = false)

Kwinjira

Mobiletto ikoresha isomero ryibiti bya winston.

Ibiti ** bizaba ** birimo inzira za dosiye nubutumwa bwamakosa, ariko ntibizigera ** birimo urufunguzo, amabanga, cyangwa andi makuru yose yo guhuza amakuru.

Urwego Urwego

Koresha ibidukikije bya MOBILETTO_LOG_LEVEL kugirango ushireho urwego rwinjira, ukoresheje imwe urwego rwa npm rwasobanuwe muri [https://www.npmjs.com/package/winston#logging-levels Igihugu (http:

Urwego rusanzwe ni error . Urwego rwinshinga cyane ni silly , nubwo kuri ubu mobiletto ntabwo yinjira kurwego munsi debug

MOBILETTO_LOG_LEVEL=silly # maximum logs!

Injira dosiye

Mburabuzi, uwandika yinjira kuri konsole. Kohereza ibiti muri dosiye, shiraho MOBILETTO_LOG_FILE ibidukikije birahinduka. Iyo winjiye muri dosiye, ibiti ntibizongera kwandikwa kuri konsole.

MOBILETTO_LOG_FILE=/var/my_mobiletto_log

Kuzimya ibiti:

MOBILETTO_LOG_FILE=/dev/null