Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

101
Visualizações
Custom fetch to mock fetch api to read data from filesystem instead of http

In my project there is a function someFunction which use fetch api to read file from http server so its slow.

I want to repalce this someFunction by my mock_someFunction which will read file from filesystem. Reading from file system would be faster then http call.

// this use http call to fetch file, this is slow
function someFunction(fileName) {
    let url = `https://${HOST}/${fileName}`
    let e = fetch(url).then(function (response) {
        // response is instance of Response
        return response.arrayBuffer();
    });
    return e;
}

// this fetch file from file system, this would be fast
function mock_someFunction(fileName) {
    // we already have this file on file system so lets not use fetch api

    let e = localFetch(fileName).then(function (response) {
        // response should be instance of Response
        return response.arrayBuffer();
    })
    return e;
}

// implement this
function localFetch(fileName) {
    // read file
    var myBlob = new Blob();
    var init = { "status" : 200 , "statusText" : "SuperSmashingGreat!" };
    var myResponse = new Response(myBlob,init);
    // return reposnce promise
}

What should be way to create mock_someFunction function to make it replaceable by someFunction?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda