MinIO is the world’s leading object storage pioneer with millions of users worldwide. On standard hardware, read/write speeds are up to 183 GB/SEC and 171 GB/SEC. Object storage can act as a primary storage layer to handle complex workloads such as Spark, Presto, TensorFlow, AND HO.ai, as well as an alternative to Hadoop HDFS. MinIO serves as the primary storage for cloud native applications, which require higher throughput and lower latency than traditional object storage. These are all performance metrics MinIO can achieve.

The cloud storage was suddenly used when I made the big screen data today, so I made a note of it.

Why MinIO

Our screen is the AI data detection analysis screen (is actually big data analysis, model study analysis of a screen), and one of them is workshop real-time anomaly detection analysis of machine tool products, so you need to deal with a lot of pictures, and pictures are ultra clear, pictures are very large, for the convenience of storage and fast reading.

The use of the MinIO

  1. Download the dependent
npm install --save minio
Copy the code
  1. Initial Minio Client (you need to set 5 properties to link to the Minio object storage service)

var Minio = require('minio')

var minioClient = new Minio.Client({
    endPoint: 'play.min.io'.port: 9000.useSSL: true.accessKey: 'Q3AM3UQ867SPQQA43P2F'.secretKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG'
});
Copy the code

3. Upload download the document address: are there in the API documentation docs.minio.org.cn/docs/master…

GetObject Downloads the object

So I’m going to focus on getObject that I’m using

let _this = this;
var size = 0;
minioClient.getObject(
  "image0".this.realTimeImage.imageData,
  function (err, dataStream) {
    if (err) {
      return console.log(err);
    }
    var newUint8Array = [];
    dataStream.on("data".function (chunk) {
      size += chunk.length;
      newUint8Array.push([...chunk]);
    });
    dataStream.on("end".function () {
      console.log("End. Total size = " + size);
      var binary = "";
      var bytes = newUint8Array.reduce((prev, cur, index, arr) = > {
        if (typeof cur == "object") {
          return prev.concat(cur);
        } else {
          prev.push(cur);
          returnprev; }} []);var len = size;
      for (var i = 0; i < len; i++) {
        binary += String.fromCharCode(bytes[i]);
      }
      let base64 = window.btoa(binary);
      _this.imgData = `data:image/jpeg; base64,${base64}`;
    });
    dataStream.on("error".function (err) {
      console.log(err); }); });Copy the code

Minor problem: Because the image file is too large, the unit8Array array returned in data is split in two, so it was a bit confusing. I realized this when I converted the unit8Array from the previous section to Base64 and realized that the image was incomplete. So we use reduce calculation and concat array merge method to merge the array again and then switch to Base64.

reduce

  1. Syntax for the Reduce method
arr.reduce(callback,[initialValue])
Copy the code

Reduce executes the callback function for each element in the array, excluding elements that were deleted or never assigned, and takes four arguments: the initial value (or the value returned by the previous callback), the current element value, the current index, and the array that called Reduce.

Callback (a function that executes each value in the array and contains four arguments)1, previousValue (the value returned from the last call to the callback, or the initialValue provided)2, currentValue (element currently being processed in array)3Index (the index of the current element in the array)4, Array (array to call reduce) initialValue (as the first parameter to call callback for the first time.Copy the code
  1. A simple use of reduce

And of course the simplest thing is the sum of arrays that we use, the product.

var  arr = [1.2.3.4];
var sum = arr.reduce((x,y) = >x+y)
var mul = arr.reduce((x,y) = >x*y)
console.log( sum ); // Sum, 10
console.log( mul ); // Take the product, 24
Copy the code
  1. Advanced use of reduce

Count the number of occurrences of each element in the array

let names = ['Joe'.'bill'.'Cathy'.'zhao money'.'Joe'];

let nameNum = names.reduce((pre,cur) = >{
  if(cur in pre){
    pre[cur]++
  }else{
    pre[cur] = 1 
  }
  return pre
},{})
console.log(nameNum); //{Zhang SAN: 2, LI Si: 1, WANG Wu: 1, Zhao Qian: 1}
Copy the code

Array to heavy

let arr = [1.3.2.4.4.2]
let newArr = arr.reduce((pre,cur) = >{
    if(! pre.includes(cur)){return pre.concat(cur)
    }else{
      return pre
    }
},[])
console.log(newArr);// [1, 2, 3, 4]
Copy the code

Convert a two-dimensional array to a one-dimensional array

let arr = [[0.1], [2.3], [4.5]]
let newArr = arr.reduce((pre,cur) = >{
    return pre.concat(cur)
},[])
console.log(newArr); // [0, 1, 2, 3, 4, 5]
Copy the code

Convert a multidimensional array to a one-dimensional one

let arr = [[0.1], [2.3], [4[5.6.7]]]
const newArr = function(arr){
   return arr.reduce((pre,cur) = >pre.concat(Array.isArray(cur)? newArr(cur):cur),[]) }console.log(newArr(arr)); //[0, 1, 2, 3, 4, 5, 6, 7]
Copy the code

The attributes of the object are summed

var person = [
    {
        name: 'Joe'.age: 18
    },
    {
        name: 'bill'.age: 12
    },
    {
        name: 'Cathy'.age: 15}];var sum = result.reduce(function(prev, cur) {
    return cur.age + prev;
}, 0);
console.log(sum) / / 45
Copy the code